Skip to content

Commit a2d80d2

Browse files
committed
Test incremental backup and restore
Signed-off-by: Matt Lord <[email protected]>
1 parent db311ed commit a2d80d2

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

test/endtoend/utils.sh

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,43 +83,81 @@ function removeBackupFiles() {
8383

8484
# takeBackup:
8585
# $1: keyspace-shard for which the backup needs to be taken
86+
declare INCREMENTAL_RESTORE_TIMESTAMP=""
8687
function takeBackup() {
8788
keyspaceShard=$1
8889
initialBackupCount=$(kubectl get vtb --no-headers | wc -l)
8990
finalBackupCount=$((initialBackupCount+1))
9091

91-
# issue the backupShard command to vtctldclient
92-
vtctldclient BackupShard "$keyspaceShard"
92+
# Issue the BackupShard command to vtctldclient.
93+
vtctldclient BackupShard "${keyspaceShard}"
9394

9495
for i in {1..600} ; do
9596
out=$(kubectl get vtb --no-headers | wc -l)
96-
echo "$out" | grep "$finalBackupCount" > /dev/null 2>&1
97-
if [ $? -eq 0 ]; then
98-
echo "Backup created"
97+
if echo "${out}" | grep -c "${finalBackupCount}" >/dev/null; then
98+
echo "Full backup created"
99+
break
100+
fi
101+
sleep 3
102+
done
103+
104+
sleep 10
105+
106+
# Now perform an incremental backup.
107+
insertWithRetry
108+
INCREMENTAL_RESTORE_TIMESTAMP=$(date -u "+%Y-%m-%dT%H:%M:%SZ")
109+
sleep 1
110+
insertWithRetry
111+
112+
sleep 10
113+
114+
vtctldclient BackupShard --incremental-from-pos=auto "${keyspaceShard}"
115+
let finalBackupCount=${finalBackupCount}+1
116+
117+
for i in {1..600} ; do
118+
out=$(kubectl get vtb --no-headers | wc -l)
119+
if echo "${out}" | grep -c "${finalBackupCount}" >/dev/null; then
120+
echo "Incremental backup created"
99121
return 0
100122
fi
101123
sleep 3
102124
done
103-
echo -e "ERROR: Backup not created - $out. $backupCount backups expected."
125+
126+
echo -e "ERROR: Backups not created - ${out}. ${backupCount} backups expected."
104127
exit 1
105128
}
106129

107130
# restoreBackup:
108131
# $1: tablet alias for which the backup needs to be restored
109132
function restoreBackup() {
110133
tabletAlias=$1
111-
if [[ -z "$tabletAlias" ]]; then
134+
if [[ -z "${tabletAlias}" ]]; then
112135
echo "Tablet alias not provided as restore target"
113136
exit 1
114137
fi
115138

116139
# Issue the PITR restore command to vtctldclient.
117-
vtctldclient RestoreFromBackup --restore-to-timestamp $(date -u "+%Y-%m-%d.%H%M%S") "${tabletAlias}"
118-
119-
if [[ $? -ne 0 ]]; then
120-
echo "Restore failed"
140+
# This should restore the last full backup, followed by applying the
141+
# binary logs to reach the desired timestamp.
142+
if ! vtctldclient RestoreFromBackup --restore-to-timestamp "${INCREMENTAL_RESTORE_TIMESTAMP}" "${tabletAlias}"; then
143+
echo "ERROR: failed to perform incremental restore"
121144
exit 1
122145
fi
146+
147+
cell="${tabletAlias%-*}"
148+
uid="${tabletAlias##*-}"
149+
150+
for i in {1..600} ; do
151+
out=$(kubectl get pods --no-headers -l "planetscale.com/cell=${cell},planetscale.com/tablet-uid=${uid}" | grep "Running" | wc -l)
152+
if echo "$out" | grep -c "1" >/dev/null; then
153+
echo "Tablet ${tabletAlias} restore complete"
154+
return 0
155+
fi
156+
sleep 3
157+
done
158+
159+
echo -e "ERROR: restored tablet ${tabletAlias} did not become healthy after the restore."
160+
exit 1
123161
}
124162

125163
function verifyListBackupsOutput() {

0 commit comments

Comments
 (0)