Skip to content

Commit ecafae2

Browse files
committed
Split out ghe-restore-settings command
1 parent 464551c commit ecafae2

2 files changed

Lines changed: 52 additions & 21 deletions

File tree

bin/ghe-restore

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,12 @@ ghe-maintenance-mode-enable "$host"
8787

8888
# Restore settings and license if performing a clean restore.
8989
if $clean_restore; then
90-
echo "Restoring settings ..."
91-
ghe-ssh "$host" -- 'ghe-import-settings' < "$GHE_RESTORE_SNAPSHOT_PATH/settings.json" 1>&3
92-
93-
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
94-
echo "Restoring license ..."
95-
ghe-ssh "$host" -- 'ghe-import-license' < "$GHE_RESTORE_SNAPSHOT_PATH/enterprise.ghl" 1>&3
96-
97-
if [ -f "$GHE_RESTORE_SNAPSHOT_PATH/manage-password" ]; then
98-
echo "Restoring management console password ..."
99-
cat "$GHE_RESTORE_SNAPSHOT_PATH/manage-password" |
100-
ghe-ssh "$host" -- \
101-
"sudo -u git dd of='$GHE_REMOTE_DATA_USER_DIR/common/manage-password' 2>&1"
102-
ghe-ssh "$host" -- \
103-
"sudo -u git chmod 0600 '$GHE_REMOTE_DATA_USER_DIR/common/manage-password'"
104-
fi
105-
106-
echo "
107-
sudo ghe-service-ensure-mysql &&
108-
sudo ghe-service-ensure-elasticsearch
109-
" | ghe-ssh "$host" -- /bin/sh 1>&3
110-
fi
90+
ghe-restore-settings "$host"
91+
92+
# Make sure mysql and elasticsearch are setup and running since this is a
93+
# fresh install which hasn't had a configure run yet.
94+
echo "sudo ghe-service-ensure-mysql && sudo ghe-service-ensure-elasticsearch" |
95+
ghe-ssh "$host" -- /bin/sh 1>&3
11196
fi
11297

11398
echo "Restoring Git repositories ..."

libexec/ghe-restore-settings

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
#/ Usage: ghe-restore-settings <host>
3+
#/ Restore settings from a snapshot to the given <host>.
4+
set -e
5+
6+
# Bring in the backup configuration
7+
cd $(dirname "$0")/..
8+
. libexec/ghe-backup-config
9+
10+
# Show usage and bail with no arguments
11+
[ -z "$*" ] && print_usage
12+
13+
# Grab host arg
14+
host="$1"
15+
16+
# Perform a host-check and establish GHE_REMOTE_XXX variables.
17+
ghe_remote_version_required "$host"
18+
19+
# The snapshot to restore should be set by the ghe-restore command but this lets
20+
# us run this script directly.
21+
: ${GHE_RESTORE_SNAPSHOT:=current}
22+
23+
# Path to snapshot dir we're restoring from
24+
GHE_RESTORE_SNAPSHOT_PATH="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT"
25+
26+
echo "Restoring settings ..."
27+
ghe-ssh "$host" -- 'ghe-import-settings' < "$GHE_RESTORE_SNAPSHOT_PATH/settings.json" 1>&3
28+
29+
# Bail out if we're restoring against a pre-2.x appliance. Everything below is
30+
# supported by v2.0 appliances only.
31+
if [ "$GHE_VERSION_MAJOR" -lt 2 ]; then
32+
exit 0
33+
fi
34+
35+
echo "Restoring license ..."
36+
ghe-ssh "$host" -- 'ghe-import-license' < "$GHE_RESTORE_SNAPSHOT_PATH/enterprise.ghl" 1>&3
37+
38+
# Restore management console password hash if present.
39+
if [ -f "$GHE_RESTORE_SNAPSHOT_PATH/manage-password" ]; then
40+
echo "Restoring management console password ..."
41+
cat "$GHE_RESTORE_SNAPSHOT_PATH/manage-password" |
42+
ghe-ssh "$host" -- \
43+
"sudo -u git dd of='$GHE_REMOTE_DATA_USER_DIR/common/manage-password' 2>&1"
44+
ghe-ssh "$host" -- \
45+
"sudo -u git chmod 0600 '$GHE_REMOTE_DATA_USER_DIR/common/manage-password'"
46+
fi

0 commit comments

Comments
 (0)