Skip to content

Commit 51c588f

Browse files
authored
Merge pull request #476 from github/taz/fix-restore-target
Restore target is ignored when specified on the command line
2 parents 3e01563 + 74f8ec8 commit 51c588f

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

bin/ghe-restore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ while true; do
6363
;;
6464
*)
6565
if [ -n "$1" ]; then
66-
GHE_RESTORE_HOST="$1"
66+
GHE_RESTORE_HOST_OPT="$1"
6767
shift
6868
else
6969
break
@@ -86,7 +86,7 @@ cleanup () {
8686
. "$( dirname "${BASH_SOURCE[0]}" )/../share/github-backup-utils/ghe-backup-config"
8787

8888
# Grab the host arg
89-
GHE_HOSTNAME="$GHE_RESTORE_HOST"
89+
GHE_HOSTNAME="${GHE_RESTORE_HOST_OPT:-$GHE_RESTORE_HOST}"
9090

9191
# Hostname without any port suffix
9292
hostname=$(echo "$GHE_HOSTNAME" | cut -f 1 -d :)

test/test-ghe-restore.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,40 @@ begin_test "ghe-restore into unconfigured vm"
188188
)
189189
end_test
190190

191+
begin_test "ghe-restore with host arg and config value"
192+
(
193+
set -e
194+
rm -rf "$GHE_REMOTE_ROOT_DIR"
195+
setup_remote_metadata
196+
197+
# set as configured, enable maintenance mode and create required directories
198+
setup_maintenance_mode "configured"
199+
200+
# set restore host environ var (which we shouldn't see)
201+
GHE_RESTORE_HOST="broken.config.restore.host"
202+
export GHE_RESTORE_HOST
203+
204+
# set restore host config var (which we shouldn't see)
205+
GHE_BACKUP_CONFIG_TEMP="${GHE_BACKUP_CONFIG}.temp"
206+
cp "$GHE_BACKUP_CONFIG" "$GHE_BACKUP_CONFIG_TEMP"
207+
echo 'GHE_RESTORE_HOST="broken.config.restore.host"' >> "$GHE_BACKUP_CONFIG_TEMP"
208+
GHE_BACKUP_CONFIG="$GHE_BACKUP_CONFIG_TEMP"
209+
export GHE_BACKUP_CONFIG
210+
211+
# run it
212+
output="$(ghe-restore -f localhost)" || false
213+
214+
# clean up the config file
215+
rm "$GHE_BACKUP_CONFIG_TEMP"
216+
217+
# verify host arg overrides configured restore host
218+
echo "$output" | grep -q 'Connect localhost:22 OK'
219+
220+
# Verify all the data we've restored is as expected
221+
verify_all_restored_data
222+
)
223+
end_test
224+
191225
begin_test "ghe-restore with host arg"
192226
(
193227
set -e
@@ -198,7 +232,7 @@ begin_test "ghe-restore with host arg"
198232
setup_maintenance_mode "configured"
199233

200234
# set restore host environ var
201-
GHE_RESTORE_HOST=127.0.0.1
235+
GHE_RESTORE_HOST="broken.environ.restore.host"
202236
export GHE_RESTORE_HOST
203237

204238
# run it

0 commit comments

Comments
 (0)