Skip to content

Commit 423f9b6

Browse files
authored
Merge pull request #291 from github/block-ha-restores
Prevent restores to an appliance in a HA pair
2 parents 1fa4f9c + 7c6bd4b commit 423f9b6

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

bin/ghe-restore

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ if $cluster; then
115115
fi
116116
fi
117117

118-
# Figure out if this instance is in a replication pair
119-
if ghe-ssh "$GHE_HOSTNAME" -- "ghe-repl-status -r 2>/dev/null" \
120-
| grep -Eq "replica|primary"; then
121-
instance_configured=true
122-
echo "WARNING: Restoring to a server with replication enabled interrupts replication."
123-
echo " You will need to reconfigure replication after the restore completes."
118+
# Figure out if this appliance is in a replication pair
119+
if ghe-ssh "$GHE_HOSTNAME" -- \
120+
"[ -f '$GHE_REMOTE_ROOT_DIR/etc/github/repl-state' ]"; then
121+
echo "Error: Restoring to an appliance with replication enabled is not supported." >&2
122+
echo " Please teardown replication before restoring." >&2
123+
exit 1
124124
fi
125125

126126
# Prompt to verify the restore host given is correct. Restoring overwrites

test/test-ghe-restore.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,24 @@ EOF
607607
echo $output | grep -q "The snapshot that is being restored contains a leaked SSH host key."
608608
)
609609
end_test
610+
611+
begin_test "ghe-restore fails when restore to an active HA pair"
612+
(
613+
set -e
614+
615+
if [ "$GHE_VERSION_MAJOR" -le 1 ]; then
616+
# noop GHE < 2.0, does not support replication
617+
exit 0
618+
fi
619+
620+
rm -rf "$GHE_REMOTE_ROOT_DIR"
621+
setup_remote_metadata
622+
623+
echo "rsync" > "$GHE_DATA_DIR/current/strategy"
624+
touch "$GHE_REMOTE_ROOT_DIR/etc/github/repl-state"
625+
626+
! output=$(ghe-restore -v -f localhost 2>&1)
627+
628+
echo $output | grep -q "Error: Restoring to an appliance with replication enabled is not supported."
629+
)
630+
end_test

0 commit comments

Comments
 (0)