-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement 40x example for backup, list backups, and restore scripts
Signed-off-by: Shail Pujan <[email protected]>
- Loading branch information
1 parent
6ae07f5
commit 790478d
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2019 The Vitess Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# This script takes backups of the 'customer' keyspace and all its shards. | ||
|
||
# Load common environment variables and functions | ||
source ../common/env.sh | ||
|
||
# Set keyspace and shard details for the 'customer' keyspace | ||
KEYSPACE="customer" | ||
SHARDS=("-80" "80-") | ||
|
||
# Helper function for logging messages with timestamps | ||
log() { | ||
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" | ||
} | ||
|
||
# Ensure the keyspace and shards are healthy | ||
log "Ensuring keyspace $KEYSPACE exists and shards are healthy..." | ||
for SHARD in "${SHARDS[@]}"; do | ||
wait_for_healthy_shard $KEYSPACE $SHARD || exit 1 | ||
done | ||
|
||
# Backup all shards of the customer keyspace | ||
for SHARD in "${SHARDS[@]}"; do | ||
log "Backing up shard $SHARD in keyspace $KEYSPACE..." | ||
vtctldclient BackupShard $KEYSPACE/$SHARD || fail "Backup failed for shard $SHARD" | ||
done | ||
|
||
log "Backup process completed successfully for all shards in $KEYSPACE." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
# Load common environment variables and functions | ||
source ../common/env.sh # Import necessary environment variables and functions from a common script | ||
|
||
# Set keyspace and shard details for the 'customer' keyspace | ||
KEYSPACE="customer" # Define the keyspace to work with | ||
SHARDS=("-80" "80-") # Define the shards within the keyspace to list backups for | ||
|
||
# Helper function for logging messages with timestamps | ||
log() { | ||
# Print a message with a timestamp | ||
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" | ||
} | ||
|
||
# List backups for each shard | ||
for SHARD in "${SHARDS[@]}"; do # Loop through each shard defined earlier | ||
log "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 | ||
done | ||
|
||
log "Backup listing process completed." # Log completion of the backup listing process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2019 The Vitess Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# This script restores the first replica tablet from backups for the 'customer' keyspace. | ||
|
||
# Load common environment variables and functions | ||
source ../common/env.sh # Import necessary environment variables and functions from a common script | ||
|
||
# Set keyspace and shard details for the 'customer' keyspace | ||
KEYSPACE="customer" # Define the keyspace to work with | ||
SHARDS=("-80" "80-") # Define the shards within the keyspace to restore | ||
|
||
# Helper function for logging messages with timestamps | ||
log() { | ||
# Print a message with a timestamp | ||
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" | ||
} | ||
|
||
# Restore all shards of the customer keyspace from backups | ||
for SHARD in "${SHARDS[@]}"; do # Loop through each shard defined earlier | ||
log "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 | ||
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 | ||
log "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 | ||
log "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 | ||
done | ||
|
||
log "Restore process completed successfully for $KEYSPACE." # Log completion of the restore process |