Skip to content

Commit 87be86f

Browse files
committed
Merge pull request #166 from github/snh/stop-multiple-restores
Prevent multiple restores from running at the same time
2 parents f013612 + f77595b commit 87be86f

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

bin/ghe-restore

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ fi
146146
echo "Starting restore of $GHE_HOSTNAME from snapshot $GHE_RESTORE_SNAPSHOT"
147147
ghe_remote_logger "Starting restore from $(hostname) / snapshot $GHE_RESTORE_SNAPSHOT ..."
148148

149-
# Update remote restore state file and setup failure trap
150-
trap "update_restore_status failed" EXIT
151-
update_restore_status "restoring"
152-
153149
# Verify the host has been fully configured at least once if when running
154150
# against v11.10.x appliances and the -c option wasn't specified.
155151
if [ "$GHE_VERSION_MAJOR" -le 1 ] && ! $restore_settings && ! $instance_configured; then
@@ -176,6 +172,16 @@ if $instance_configured; then
176172
fi
177173
fi
178174

175+
# Make sure the appliance doesn't already have a restore underway
176+
if [ "$GHE_VERSION_MAJOR" -ge 2 ] && ghe-ssh "$GHE_HOSTNAME" -- "sudo grep -q restoring $GHE_REMOTE_DATA_USER_DIR/common/ghe-restore-status 2>/dev/null"; then
177+
echo "Error: $GHE_HOSTNAME already has a restore underway. Aborting." 1>&2
178+
exit 1
179+
fi
180+
181+
# Update remote restore state file and setup failure trap
182+
trap "update_restore_status failed" EXIT
183+
update_restore_status "restoring"
184+
179185
# Restore settings and license if restoring to an unconfigured appliance or when
180186
# specified manually.
181187
if $restore_settings; then

test/test-ghe-restore.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,37 @@ begin_test "ghe-restore with tarball strategy"
410410
echo "$output" | grep -q 'fake ghe-export-repositories data'
411411
)
412412
end_test
413+
414+
begin_test "ghe-restore aborts when another restore is underway"
415+
(
416+
set -e
417+
# This test is only valid for version 2 and above
418+
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
419+
rm -rf "$GHE_REMOTE_ROOT_DIR"
420+
setup_remote_metadata
421+
422+
# create file used to determine if instance has been configured.
423+
touch "$GHE_REMOTE_ROOT_DIR/etc/github/configured"
424+
425+
# create file used to determine if instance is in maintenance mode.
426+
mkdir -p "$GHE_REMOTE_DATA_DIR/github/current/public/system"
427+
touch "$GHE_REMOTE_DATA_DIR/github/current/public/system/maintenance.html"
428+
429+
# create file to indicate restore is underway
430+
echo "restoring" > "$GHE_REMOTE_DATA_USER_DIR/common/ghe-restore-status"
431+
432+
# set restore host environ var
433+
GHE_RESTORE_HOST=127.0.0.1
434+
export GHE_RESTORE_HOST
435+
436+
# run ghe-restore and write output to file for asserting against
437+
# this should fail due to the appliance being in an unconfigured state
438+
! ghe-restore -v > "$TRASHDIR/restore-out" 2>&1
439+
440+
cat $TRASHDIR/restore-out
441+
442+
# verify that ghe-restore failed due a restore already being underway
443+
grep -q -e "already has a restore underway" "$TRASHDIR/restore-out"
444+
fi
445+
)
446+
end_test

0 commit comments

Comments
 (0)