Skip to content

Commit

Permalink
add user to env&script
Browse files Browse the repository at this point in the history
Signed-off-by: wkd-woo <[email protected]>
  • Loading branch information
wkd-woo committed Mar 3, 2024
1 parent 0e54f3b commit 3f611ef
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions example/v1beta2/backup_restore/backup/env-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ stringData:
RESTIC_PASSWORD: abc@123
RESTIC_CACHE_DIR: "/tmp/restic_cache"
REDIS_PORT: "6379"
REDIS_USERNAME: "default"
REDIS_PASSWORD: ""
BACKUP_DESTINATION: AWS_S3
AWS_S3_BUCKET: shubham-redis
Expand Down
8 changes: 6 additions & 2 deletions scripts/backup/backup-user.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e # Exit on error
DEFAULT_CLUSTER_NAME="redis-cluster"
DEFAULT_CLUSTER_NAMESPACE="default"
DEFAULT_REDIS_PORT="6379"
DEFAULT_REDIS_USERNAME="default"
DEFAULT_REDIS_PASSWORD=""

# Prompt the user for input or use default values
Expand All @@ -18,6 +19,9 @@ CLUSTER_NAMESPACE=${CLUSTER_NAMESPACE:-$DEFAULT_CLUSTER_NAMESPACE}
read -p "Enter Redis port [$DEFAULT_REDIS_PORT]: " REDIS_PORT
REDIS_PORT=${REDIS_PORT:-$DEFAULT_REDIS_PORT}

read -p "Enter Redis username [DEFAULT_REDIS_USERNAME]: " REDIS_USERNAME
REDIS_USERNAME=${REDIS_USERNAME:-DEFAULT_REDIS_USERNAME}

read -p "Enter Redis password [$DEFAULT_REDIS_PASSWORD]: " REDIS_PASSWORD
REDIS_PASSWORD=${REDIS_PASSWORD:-$DEFAULT_REDIS_PASSWORD}

Expand Down Expand Up @@ -59,7 +63,7 @@ REDIS_HOST="${CLUSTER_NAME}-leader-0.${CLUSTER_NAME}-leader-headless.${CLUSTER_N

# Check the Total Leader Present in Redis Cluster using cr and redis-cli
TOTAL_LEADERS=$(kubectl get redisclusters.redis.redis.opstreelabs.in "${CLUSTER_NAME}" -n "${CLUSTER_NAMESPACE}" -o jsonpath='{.spec.redisLeader.replicas}')
MASTERS_IP=($(redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" -a "$REDIS_PASSWORD" --no-auth-warning cluster nodes | grep "master" | awk '{print $2}' | cut -d "@" -f1))
MASTERS_IP=($(redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --username "$REDIS_USERNAME" -a "$REDIS_PASSWORD" --no-auth-warning cluster nodes | grep "master" | awk '{print $2}' | cut -d "@" -f1))

check_total_leaders_from_cr() {
if [[ -z "$TOTAL_LEADERS" || "$TOTAL_LEADERS" == 0 ]]; then
Expand Down Expand Up @@ -108,7 +112,7 @@ perform_redis_backup(){
echo "Performing backup on Redis instance at $IP:$PORT"

# Copy the file from the Redis instance to a local file
redis-cli -h "$IP" -p "$PORT" -a "$REDIS_PASSWORD" --rdb "/tmp/${POD}.rdb"
redis-cli -h "$IP" -p "$PORT" --username "$REDIS_USERNAME" -a "$REDIS_PASSWORD" --rdb "/tmp/${POD}.rdb"

# Upload the file to the selected backup destination using restic
restic -r "$RESTIC_REPOSITORY" backup "/tmp/${POD}.rdb" --host "${CLUSTER_NAME}_${CLUSTER_NAMESPACE}" --tag "${POD}" --tag "redis"
Expand Down
4 changes: 2 additions & 2 deletions scripts/backup/backup-v0.15.1.bash
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ REDIS_HOST="${CLUSTER_NAME}-leader-0.${CLUSTER_NAME}-leader-headless.${CLUSTER_N

# Check the Total Leader Present in Redis Cluster using cr and redis-cli
TOTAL_LEADERS=$(kubectl get redisclusters.redis.redis.opstreelabs.in "${CLUSTER_NAME}" -n "${CLUSTER_NAMESPACE}" -o jsonpath='{.spec.redisLeader.replicas}')
MASTERS_IP=($(redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" -a "$REDIS_PASSWORD" --no-auth-warning cluster nodes | grep "master" | awk '{print $2}' | cut -d "@" -f1))
MASTERS_IP=($(redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --username "$REDIS_USERNAME" -a "$REDIS_PASSWORD" --no-auth-warning cluster nodes | grep "master" | awk '{print $2}' | cut -d "@" -f1))

check_total_leaders_from_cr() {
if [[ -z "$TOTAL_LEADERS" || "$TOTAL_LEADERS" == 0 ]]; then
Expand Down Expand Up @@ -73,7 +73,7 @@ perform_redis_backup(){
echo "Performing backup on Redis instance at $IP:$PORT"

# Copy the file from the Redis instance to a local file
redis-cli -h "$IP" -p "$PORT" -a "$REDIS_PASSWORD" --rdb "/tmp/${POD}.rdb"
redis-cli -h "$IP" -p "$PORT" --username "$REDIS_USERNAME" -a "$REDIS_PASSWORD" --rdb "/tmp/${POD}.rdb"

# Upload the file to the selected backup destination using restic
restic -r "$RESTIC_REPOSITORY" backup "/tmp/${POD}.rdb" --host "${CLUSTER_NAME}_${CLUSTER_NAMESPACE}" --tag "${POD}" --tag "redis"
Expand Down
4 changes: 2 additions & 2 deletions scripts/backup/backup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ REDIS_HOST="${CLUSTER_NAME}-leader-0.${CLUSTER_NAME}-leader-headless.${CLUSTER_N

# Check the Total Leader Present in Redis Cluster using cr and redis-cli
TOTAL_LEADERS=$(kubectl get redisclusters.redis.redis.opstreelabs.in "${CLUSTER_NAME}" -n "${CLUSTER_NAMESPACE}" -o jsonpath='{.spec.redisLeader.replicas}')
MASTERS_IP=($(redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" -a "$REDIS_PASSWORD" --no-auth-warning cluster nodes | grep "master" | awk '{print $2}' | cut -d "@" -f1))
MASTERS_IP=($(redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --username "$REDIS_USERNAME" -a "$REDIS_PASSWORD" --no-auth-warning cluster nodes | grep "master" | awk '{print $2}' | cut -d "@" -f1))

check_total_leaders_from_cr() {
# Check if TOTAL_LEADERS is 0 or nil
Expand Down Expand Up @@ -73,7 +73,7 @@ perform_redis_backup(){
echo "Performing backup on Redis instance at $IP:$PORT"

# Copy the file from the Redis instance to a local file
redis-cli -h "$IP" -p "$PORT" -a "$REDIS_PASSWORD" --rdb "/tmp/${POD}.rdb"
redis-cli -h "$IP" -p "$PORT" --username "$REDIS_USERNAME" -a "$REDIS_PASSWORD" --rdb "/tmp/${POD}.rdb"

# Upload the file to the selected backup destination using restic
restic -r "$RESTIC_REPOSITORY" backup "/tmp/${POD}.rdb" --host "${CLUSTER_NAME}_${CLUSTER_NAMESPACE}" --tag "${POD}" --tag "redis"
Expand Down
1 change: 1 addition & 0 deletions scripts/backup/env_vars.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export RESTIC_CACHE_DIR=/tmp/restic_cache

# Redis
export DEFAULT_REDIS_PORT="6379"
export DEFAULT_REDIS_USERNAME="default"
export DEFAULT_REDIS_PASSWORD=""

# Backup destination
Expand Down
1 change: 1 addition & 0 deletions scripts/env_vars.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export RESTIC_CACHE_DIR=/tmp/restic_cache
# Redis
export DEFAULT_REDIS_HOST="redis-cluster-leader-0"
export DEFAULT_REDIS_PORT="6379"
export DEFAULT_REDIS_USERNAME="default"
export DEFAULT_REDIS_PASSWORD=""

# Backup destination
Expand Down
2 changes: 1 addition & 1 deletion scripts/restore/env_vars.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export RESTIC_CACHE_DIR=/tmp/restic_cache

# Redis
export DEFAULT_REDIS_PORT="6379"
export DEFAULT_REDIS_USERNAME="default"
export DEFAULT_REDIS_PASSWORD=""

# Backup destination

export BACKUP_DESTINATION=AWS_S3

# AWS
Expand Down

0 comments on commit 3f611ef

Please sign in to comment.