Skip to content

Commit adde328

Browse files
authored
Add incremental MySQL restore test (#530)
Add basic tests for incremental MySQL restores
1 parent 2949a8f commit adde328

File tree

3 files changed

+120
-1
lines changed

3 files changed

+120
-1
lines changed

test/test-ghe-host-check.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ begin_test "ghe-host-check detects unsupported GitHub Enterprise Server versions
8383
ix=$(( $ix + 1 ))
8484
done
8585
GHE_TEST_REMOTE_VERSION="${keys[$ix]}.0" ghe-host-check
86-
GHE_TEST_REMOTE_VERSION="${keys[$(( $ix - 1 ))]}.0" ghe-host-check
86+
# sometimes when the latest.json is updated during a release this test gets broken.
87+
if [ "${keys[$(( $ix - 1 ))]}" != "latest" ]; then
88+
GHE_TEST_REMOTE_VERSION="${keys[$(( $ix - 1 ))]}.0" ghe-host-check
89+
fi
8790
GHE_TEST_REMOTE_VERSION="${keys[$(( $ix - 2 ))]}.0" ghe-host-check
8891

8992
fi

test/test-ghe-incremental-restore.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
# ghe-restore command tests
3+
4+
# Bring in testlib
5+
# shellcheck source=test/testlib.sh
6+
. "$(dirname "$0")/testlib.sh"
7+
8+
setup_incremental_restore_data
9+
setup_actions_enabled_settings_for_restore true
10+
11+
# Make the current symlink
12+
ln -s 1 "$GHE_DATA_DIR/current"
13+
begin_test "ghe_restore -i doesn't run on unsupported versions"
14+
(
15+
set -e
16+
GHE_RESTORE_HOST=127.0.0.1
17+
export GHE_RESTORE_HOST
18+
19+
# restore should fail on versions older than 3.10
20+
! GHE_TEST_REMOTE_VERSION=3.9.0 ghe-restore -i -v
21+
! GHE_TEST_REMOTE_VERSION=3.7.0 ghe-restore -i -v
22+
! GHE_TEST_REMOTE_VERSION=3.1.0 ghe-restore -i -v
23+
)
24+
end_test
25+
26+
begin_test "ghe-restore -i into configured vm from full backup"
27+
(
28+
set -e
29+
rm -rf "$GHE_REMOTE_ROOT_DIR"
30+
setup_remote_metadata
31+
32+
# set as configured, enable maintenance mode and create required directories
33+
setup_maintenance_mode "configured"
34+
35+
# set restore host environ var
36+
GHE_RESTORE_HOST=127.0.0.1
37+
export GHE_RESTORE_HOST
38+
# run ghe-restore and write output to file for asserting against
39+
if ! GHE_TEST_REMOTE_VERSION=3.10.0 GHE_DEBUG=1 ghe-restore -i -v -f > "$TRASHDIR/restore-out" 2>&1; then
40+
output_debug_logs_and_fail_test
41+
fi
42+
43+
44+
# verify connect to right host
45+
grep -q "Connect 127.0.0.1:122 OK" "$TRASHDIR/restore-out"
46+
47+
# verify stale servers were cleared
48+
grep -q "Cleaning up stale nodes ..." "$TRASHDIR/restore-out"
49+
50+
# Verify all the data we've restored is as expected
51+
verify_all_restored_data
52+
)
53+
end_test
54+
55+
begin_test "ghe-restore -i fails when the lsn information for the listed files is out of order"
56+
(
57+
set -e
58+
rm -rf "$GHE_REMOTE_ROOT_DIR"
59+
setup_remote_metadata
60+
61+
# set as configured, enable maintenance mode and create required directories
62+
setup_maintenance_mode "configured"
63+
64+
# set restore host environ var
65+
GHE_RESTORE_HOST=127.0.0.1
66+
export GHE_RESTORE_HOST
67+
68+
inc_1="$GHE_DATA_DIR/2"
69+
inc_2="$GHE_DATA_DIR/3"
70+
71+
# screw up the order of the LSNs in xtrabackup_checkpoints
72+
setup_incremental_lsn $inc_1 100 200 incremental
73+
setup_incremental_lsn $inc_2 50 50 incremental
74+
# run ghe-restore and write output to file for asserting against
75+
# we expect failure and need the right output.
76+
if GHE_DEBUG=1 ghe-restore -i -v -f > "$TRASHDIR/restore-out" 2>&1; then
77+
true
78+
fi
79+
)
80+
end_test
81+
82+

test/testlib.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,40 @@ setup_test_data () {
327327
setup_minio_test_data "$GHE_DATA_DIR"
328328
}
329329

330+
# Sets up test data for testing incremental restores.
331+
setup_incremental_restore_data() {
332+
local full="$GHE_DATA_DIR/1"
333+
local inc_1="$GHE_DATA_DIR/2"
334+
local inc_2="$GHE_DATA_DIR/3"
335+
# Run the setup_test_data function to create three directories: 1 for full backup and two incremental.
336+
# we can use these directories for different types of tests
337+
setup_test_data "$full"
338+
setup_test_data "$inc_1"
339+
setup_test_data "$inc_2"
340+
# Setup the metadata files that track which files are used to track full and incremental files
341+
echo "$full" >> "$GHE_DATA_DIR/inc_full_backup"
342+
echo -e "$inc_1\n$inc_2" >> "$GHE_DATA_DIR/inc_snapshot_data"
343+
# Configure lsn data in xtrabackup_checkpoints for the full backup and the incremental backup
344+
setup_incremental_lsn $full 1 100 full
345+
setup_incremental_lsn $inc_1 101 200 incremental
346+
setup_incremental_lsn $inc_2 201 300 incremental
347+
}
348+
349+
setup_incremental_lsn() {
350+
local loc=$1
351+
local start=$2
352+
local end=$3
353+
local type=$4
354+
355+
cat <<LSN >> "$loc/xtrabackup_checkpoints"
356+
backup_type = $type
357+
from_lsn = $start
358+
to_lsn = $end
359+
last_lsn = $end
360+
flushed_lsn = $end
361+
LSN
362+
}
363+
330364
setup_incremental_backup_config() {
331365
ghe-ssh "$GHE_HOSTNAME" -- 'mkdir -p /tmp/lsndir'
332366
ghe-ssh "$GHE_HOSTNAME" -- 'echo "fake xtrabackup checkpoint" > /tmp/lsndir/xtrabackup_checkpoints'

0 commit comments

Comments
 (0)