Skip to content

Commit e624b6b

Browse files
committed
Split out ghe-backup-settings command
1 parent ecafae2 commit e624b6b

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

bin/ghe-backup

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,9 @@ if [ "$GHE_BACKUP_STRATEGY" = "tarball" ]; then
9191
fi
9292

9393
echo "Backing up GitHub settings ..."
94-
ghe-ssh "$host" -- 'ghe-export-settings' > settings.json ||
94+
ghe-backup-settings ||
9595
failures="$failures settings"
9696

97-
# transfer license file
98-
ghe-ssh "$host" -- "cat '$GHE_REMOTE_LICENSE_FILE'" > enterprise.ghl ||
99-
failures="$failures license"
100-
101-
# transfer enterprise manage password hash if running against a v2.x instance.
102-
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
103-
manage_password_file="$GHE_REMOTE_DATA_USER_DIR/common/manage-password"
104-
if echo "sudo cat '$manage_password_file' 2>/dev/null || true" |
105-
ghe-ssh "$host" -- /bin/sh > manage-password+
106-
then
107-
if [ -n "$(cat manage-password+)" ]; then
108-
mv manage-password+ manage-password
109-
fi
110-
else
111-
unlink manage-password+
112-
failures="$failures manage-password"
113-
fi
114-
fi
115-
11697
echo "Backing up SSH authorized keys ..."
11798
ghe-ssh "$host" -- 'ghe-export-authorized-keys' > authorized-keys.json ||
11899
failures="$failures authorized-keys"

libexec/ghe-backup-settings

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
#/ Usage: ghe-backup-settings
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+
# Perform a host-check and establish GHE_REMOTE_XXX variables.
11+
ghe_remote_version_required "$host"
12+
13+
# Grab the host
14+
host="$GHE_HOSTNAME"
15+
16+
# Create the snapshot directory if needed and change into it.
17+
mkdir -p "$GHE_SNAPSHOT_DIR"
18+
cd "$GHE_SNAPSHOT_DIR"
19+
20+
echo "* Transferring settings data ..." 1>&3
21+
ghe-ssh "$host" -- 'ghe-export-settings' > settings.json
22+
23+
echo "* Transferring license data ..." 1>&3
24+
ghe-ssh "$host" -- "cat '$GHE_REMOTE_LICENSE_FILE'" > enterprise.ghl
25+
26+
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
27+
echo "* Transferring management console password ..." 1>&3
28+
manage_password_file="$GHE_REMOTE_DATA_USER_DIR/common/manage-password"
29+
if echo "sudo cat '$manage_password_file' 2>/dev/null || true" |
30+
ghe-ssh "$host" -- /bin/sh > manage-password+
31+
then
32+
if [ -n "$(cat manage-password+)" ]; then
33+
mv manage-password+ manage-password
34+
fi
35+
else
36+
unlink manage-password+
37+
fi
38+
fi

0 commit comments

Comments
 (0)