Skip to content

Commit 2247105

Browse files
committed
Prompt for confirmation before restoring
This should reduce the chances of someone accidentally restoring to the incorrect host (like the backup host). The prompt can be avoided by passing -f or --force to the ghe-restore command.
1 parent 35f0239 commit 2247105

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

bin/ghe-restore

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#/ argument is provided, it always overrides the configured restore host.
77
#/
88
#/ Options:
9+
#/ -f Don't prompt for confirmation before restoring.
910
#/ -c Restore appliance settings and license in addition to
1011
#/ datastores. Settings are not restored by default to
1112
#/ prevent overwriting different configuration on the
@@ -32,8 +33,13 @@ export GHE_RESTORE_SNAPSHOT
3233

3334
# Parse arguments
3435
restore_settings=false
36+
force=false
3537
while true; do
3638
case "$1" in
39+
-f|--force)
40+
force=true
41+
shift
42+
;;
3743
-s)
3844
GHE_RESTORE_SNAPSHOT="$(basename "$2")"
3945
shift 2
@@ -70,11 +76,39 @@ GHE_RESTORE_SNAPSHOT=$(basename "$GHE_RESTORE_SNAPSHOT_PATH")
7076
# strategy file written in the snapshot directory.
7177
GHE_BACKUP_STRATEGY=$(cat "$GHE_RESTORE_SNAPSHOT_PATH/strategy")
7278

73-
echo "Starting $GHE_BACKUP_STRATEGY restore of $host from snapshot $GHE_RESTORE_SNAPSHOT"
74-
7579
# Perform a host-check and establish the remote version in GHE_REMOTE_VERSION.
7680
ghe_remote_version_required "$host"
7781

82+
# Prompt to verify the restore host given is correct. Restoring overwrites
83+
# important data on the destination appliance that cannot be recovered. This is
84+
# mostly to prevent accidents where the backup host is given to restore instead
85+
# of a separate restore host since they're used in such close proximity.
86+
if ! $force; then
87+
echo
88+
echo "WARNING: All data on GitHub Enterprise appliance $hostname ($GHE_REMOTE_VERSION)"
89+
echo " will be overwritten with data from snapshot ${GHE_RESTORE_SNAPSHOT}."
90+
echo "Please verify that this is the correct restore host before continuing."
91+
printf "Type 'yes' to continue: "
92+
93+
while read -r response; do
94+
case $response in
95+
yes|Yes|YES)
96+
break
97+
;;
98+
'')
99+
printf "Type 'yes' to continue: "
100+
;;
101+
*)
102+
echo "Restore aborted." 1>&2
103+
exit 1
104+
;;
105+
esac
106+
done
107+
echo
108+
fi
109+
110+
echo "Starting $GHE_BACKUP_STRATEGY restore of $host from snapshot $GHE_RESTORE_SNAPSHOT"
111+
78112
# Verify the host has been fully configured at least once unless the -c
79113
# argument was provided.
80114
if ! $restore_settings &&

0 commit comments

Comments
 (0)