diff --git a/examples/local/401_backup.sh b/examples/local/401_backup.sh index 8019cb6d107..a8e0bffc3e0 100755 --- a/examples/local/401_backup.sh +++ b/examples/local/401_backup.sh @@ -19,14 +19,22 @@ SHARDS=("-80" "80-") # Ensure the keyspace and shards are healthy echo "Ensuring keyspace $KEYSPACE exists and shards are healthy..." -for shard in "${shards[@]}"; do - wait_for_healthy_shard "$KEYSPACE" "$shard" || exit 1 +for shard in "${SHARDS[@]}"; do + if ! wait_for_healthy_shard "$KEYSPACE" "$shard"; then + echo "Shard $shard is not healthy. Exiting..." + exit 1 + fi done # Backup all shards of the customer keyspace -for shard in "${shards[@]}"; do +for shard in "${SHARDS[@]}"; do echo "Backing up shard $shard in keyspace $KEYSPACE..." - vtctldclient BackupShard "$KEYSPACE/$shard" || fail "Backup failed for shard $shard" + if vtctldclient BackupShard "$KEYSPACE/$shard"; then + echo "Backup succeeded for shard $shard." + else + echo "Backup failed for shard $shard." + exit 1 + fi done -echo "Backup process completed successfully for all shards in $KEYSPACE." \ No newline at end of file +echo "Backup process completed successfully for all shards in $KEYSPACE." diff --git a/examples/local/402_list_backup.sh b/examples/local/402_list_backup.sh index 79b3621ca59..a0a90fff7f7 100755 --- a/examples/local/402_list_backup.sh +++ b/examples/local/402_list_backup.sh @@ -8,9 +8,9 @@ KEYSPACE="customer" # Define the keyspace to work with SHARDS=("-80" "80-") # Define the shards within the keyspace to list backups for # List backups for each shard -for SHARD in "${SHARDS[@]}"; do # Loop through each shard defined earlier - echo "Listing available backups for keyspace $KEYSPACE and shard $SHARD..." # Log the start of the backup listing - vtctldclient GetBackups $KEYSPACE/$SHARD || log "Failed to list backups for keyspace $KEYSPACE and shard $SHARD" # Attempt to list backups; log failure if it occurs +for shard in "${SHARDS[@]}"; do # Loop through each shard defined earlier + echo "Listing available backups for keyspace $KEYSPACE and shard $shard..." # Log the start of the backup listing + vtctldclient GetBackups "$KEYSPACE/$shard" || echo "Failed to list backups for keyspace $KEYSPACE and shard $shard" # Attempt to list backups; log failure if it occurs done echo "Backup listing process completed." # Log completion of the backup listing process diff --git a/examples/local/403_restore_from_backup.sh b/examples/local/403_restore_from_backup.sh index 3d190f6127d..66985e996eb 100755 --- a/examples/local/403_restore_from_backup.sh +++ b/examples/local/403_restore_from_backup.sh @@ -18,20 +18,25 @@ KEYSPACE="customer" # Define the keyspace to work with SHARDS=("-80" "80-") # Define the shards within the keyspace to restore # Restore all shards of the customer keyspace from backups -for SHARD in "${SHARDS[@]}"; do # Loop through each shard defined earlier - echo "Finding replica tablets for shard $SHARD..." # Log the start of the tablet search - REPLICA_TABLETS=$(vtctldclient GetTablets --keyspace=$KEYSPACE --shard=$SHARD --tablet-type=replica | awk '{print $1}') # Fetch replica tablets for the current shard +for shard in "${SHARDS[@]}"; do # Loop through each shard defined earlier + echo "Finding replica tablets for shard $shard..." # Log the start of the tablet search + + # Fetch the list of replica tablets for the current shard + REPLICA_TABLETS=$(vtctldclient GetTablets --keyspace="$KEYSPACE" --shard="$shard" --tablet-type=replica | awk '{print $1}') # Extract the first column containing tablet names REPLICA_COUNT=$(echo "$REPLICA_TABLETS" | wc -l) # Count the number of replica tablets found - if [ "$REPLICA_COUNT" -lt 1 ]; then # Check if no replica tablets were found - echo "No replica tablets found for shard $SHARD. Exiting..." # Log a message and exit if none are found + # Check if any replica tablets were found + if [ "$REPLICA_COUNT" -lt 1 ]; then # If the count is less than 1, no replicas were found + echo "No replica tablets found for shard $shard. Exiting..." # Log a message and exit if none are found exit 1 # Exit the script with an error code fi # Choose the first replica for restoration RESTORE_TABLET=$(echo "$REPLICA_TABLETS" | head -n 1) # Select the first replica tablet from the list - echo "Restoring tablet $RESTORE_TABLET from backup for shard $SHARD..." # Log the restoration action - vtctldclient RestoreFromBackup $RESTORE_TABLET || fail "Restore failed for tablet $RESTORE_TABLET" # Restore from backup and handle any failures + echo "Restoring tablet $RESTORE_TABLET from backup for shard $shard..." # Log the restoration action + + # Restore from backup and handle any failures + vtctldclient RestoreFromBackup "$RESTORE_TABLET" || fail "Restore failed for tablet $RESTORE_TABLET" # Attempt to restore from backup and log an error message if it fails done echo "Restore process completed successfully for $KEYSPACE." # Log completion of the restore process