Skip to content

Commit d59458d

Browse files
authored
Merge branch 'master' into snh/benchmark-init
2 parents a599322 + fa17fa8 commit d59458d

File tree

10 files changed

+78
-10
lines changed

10 files changed

+78
-10
lines changed

bin/ghe-backup

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
#/ Usage: ghe-backup [-v]
2+
#/ Usage: ghe-backup [-v] [--version]
33
#/ Take snapshots of all GitHub Enterprise data, including Git repository data,
44
#/ the MySQL database, instance settings, GitHub Pages data, etc.
55
#/
@@ -162,11 +162,11 @@ if [ $GHE_VERSION_MAJOR -ge 2 ]; then
162162
echo "Backing up audit log ..."
163163
ghe-backup-es-audit-log ||
164164
failures="$failures audit-log"
165-
fi
166165

167-
echo "Backing up hookshot logs ..."
168-
ghe-backup-es-hookshot ||
169-
failures="$failures hookshot"
166+
echo "Backing up hookshot logs ..."
167+
ghe-backup-es-hookshot ||
168+
failures="$failures hookshot"
169+
fi
170170

171171
echo "Backing up Git repositories ..."
172172
if [ "$GHE_BACKUP_STRATEGY" = "cluster" ]; then

bin/ghe-restore

Lines changed: 4 additions & 3 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+
#/ --version Display version information.
910
#/ -f Don't prompt for confirmation before restoring.
1011
#/ -c Restore appliance settings and license in addition to
1112
#/ datastores. Settings are not restored by default to
@@ -330,14 +331,14 @@ fi
330331
if $cluster; then
331332
echo "Restoring ElasticSearch Audit logs"
332333
ghe-restore-es-audit-log "$GHE_HOSTNAME" 1>&3
334+
335+
echo "Restoring hookshot logs ..."
336+
ghe-restore-es-hookshot "$GHE_HOSTNAME" 1>&3
333337
else
334338
echo "Restoring Elasticsearch indices ..."
335339
ghe-restore-es-${GHE_BACKUP_STRATEGY} "$GHE_HOSTNAME" 1>&3
336340
fi
337341

338-
echo "Restoring hookshot logs ..."
339-
ghe-restore-es-hookshot "$GHE_HOSTNAME" 1>&3
340-
341342
# Restart an already running memcached to reset the cache after restore
342343
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
343344
echo "Restarting memcached ..." 1>&3

share/github-backup-utils/ghe-backup-config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ PATH="$GHE_BACKUP_ROOT/bin:$GHE_BACKUP_ROOT/share/github-backup-utils:$PATH"
2525

2626
. $GHE_BACKUP_ROOT/share/github-backup-utils/bm.sh
2727

28+
# Display version string if flag present for any command
29+
if [ "$1" = "--version" ]; then
30+
echo "GitHub backup-utils v$BACKUP_UTILS_VERSION"
31+
exit 0
32+
fi
33+
2834
# Parse out -v (verbose) argument
2935
if [ "$1" = "-v" ]; then
3036
GHE_VERBOSE=true
@@ -83,6 +89,18 @@ if [ ${GHE_DATA_DIR:0:1} != "/" ]; then
8389
GHE_DATA_DIR="$( cd "$GHE_BACKUP_ROOT" && readlink -m "$GHE_DATA_DIR" 2> /dev/null || echo "$GHE_BACKUP_ROOT/$GHE_DATA_DIR" )"
8490
fi
8591

92+
# Assign the Release File path if it hasn't been provided (eg: by test suite)
93+
: ${GHE_RELEASE_FILE:="/etc/github/enterprise-release"}
94+
95+
# Check that utils are not being run directly on GHE appliance.
96+
if [ -f "$GHE_RELEASE_FILE" ]; then
97+
echo "Error: Backup Utils cannot be run on the GitHub Enterprise host." 1>&2
98+
echo " The backup utilities should be run on a host dedicated to" 1>&2
99+
echo " long-term permanent storage and must have network connectivity" 1>&2
100+
echo " with the GitHub Enterprise appliance." 1>&2
101+
exit 1
102+
fi
103+
86104
GHE_CREATE_DATA_DIR=${GHE_CREATE_DATA_DIR:-yes}
87105

88106
# Check that the data directory is set and create it if it doesn't exist.

share/github-backup-utils/ghe-backup-settings

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#/ Usage: ghe-backup-settings
3-
#/ Restore settings from a snapshot to the given <host>.
3+
#/ Backup settings from a snapshot to the given <host>.
44
set -e
55

66
# Bring in the backup configuration
@@ -45,6 +45,11 @@ if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
4545
fi
4646
fi
4747

48+
if ghe-ssh "$host" -- "which ghe-export-ssl-ca-certificates 1>/dev/null"; then
49+
echo "* Transferring CA certificates ..." 1>&3
50+
ghe-ssh "$host" -- "ghe-export-ssl-ca-certificates" > ssl-ca-certificates.tar
51+
fi
52+
4853
if [ "$GHE_BACKUP_STRATEGY" = "cluster" ]; then
4954
echo "* Transferring cluster configuration ..." 1>&3
5055
if ! ghe-ssh "$host" -- "sudo cat $GHE_REMOTE_CLUSTER_CONF_FILE 2>/dev/null" > cluster.conf; then

share/github-backup-utils/ghe-restore-settings

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,11 @@ if [ -f "$GHE_RESTORE_SNAPSHOT_PATH/saml-keys.tar" ]; then
5858
ghe-ssh "$GHE_HOSTNAME" -- "sudo tar -C $GHE_REMOTE_DATA_USER_DIR/common/ -xf -"
5959
fi
6060

61+
# Restore CA certificates if present.
62+
if [ -f "$GHE_RESTORE_SNAPSHOT_PATH/ssl-ca-certificates.tar" ]; then
63+
echo "Restoring CA certificates ..."
64+
cat "$GHE_RESTORE_SNAPSHOT_PATH/ssl-ca-certificates.tar" |
65+
ghe-ssh "$GHE_HOSTNAME" -- "ghe-import-ssl-ca-certificates"
66+
fi
67+
6168
bm_start "$(basename $0)"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ghe-fake-export-command
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ghe-fake-import-command

test/test-ghe-backup-config.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ begin_test "ghe-backup-config GHE_CREATE_DATA_DIR disabled"
4141
)
4242
end_test
4343

44+
begin_test "ghe-backup-config run on GHE appliance"
45+
(
46+
set -e
47+
48+
export GHE_RELEASE_FILE="$TRASHDIR/enterprise-release"
49+
touch "$GHE_RELEASE_FILE"
50+
set +e
51+
error=$(. share/github-backup-utils/ghe-backup-config 2>&1)
52+
# should exit 1
53+
if [ $? != 1 ]; then
54+
exit 1
55+
fi
56+
set -e
57+
echo "$error" | grep -q "Error: Backup Utils cannot be run on the GitHub Enterprise host."
58+
59+
test -f "$GHE_RELEASE_FILE"
60+
rm -rf "$GHE_RELEASE_FILE"
61+
)
62+
end_test
63+
4464
begin_test "ghe-backup-config ssh_host_part"
4565
(
4666
set -e
@@ -51,7 +71,6 @@ begin_test "ghe-backup-config ssh_host_part"
5171
)
5272
end_test
5373

54-
5574
begin_test "ghe-backup-config ssh_port_part"
5675
(
5776
set -e

test/test-ghe-backup.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ begin_test "ghe-backup first snapshot"
151151

152152
# verify the UUID was transferred
153153
diff -ru "$GHE_REMOTE_DATA_USER_DIR/common/uuid" "$GHE_DATA_DIR/current/uuid"
154+
155+
# check that ca certificates were backed up
156+
[ "$(cat "$GHE_DATA_DIR/current/ssl-ca-certificates.tar")" = "fake ghe-export-ssl-ca-certificates data" ]
154157
fi
155158

156159
# verify that ghe-backup wrote its version information to the host
@@ -235,6 +238,9 @@ begin_test "ghe-backup subsequent snapshot"
235238

236239
# verify the UUID was transferred
237240
diff -ru "$GHE_REMOTE_DATA_USER_DIR/common/uuid" "$GHE_DATA_DIR/current/uuid"
241+
242+
# check that ca certificates were backed up
243+
[ "$(cat "$GHE_DATA_DIR/current/ssl-ca-certificates.tar")" = "fake ghe-export-ssl-ca-certificates data" ]
238244
fi
239245
)
240246
end_test
@@ -335,6 +341,9 @@ begin_test "ghe-backup with relative data dir path"
335341

336342
# verify the UUID was transferred
337343
diff -ru "$GHE_REMOTE_DATA_USER_DIR/common/uuid" "$GHE_DATA_DIR/current/uuid"
344+
345+
# check that ca certificates were backed up
346+
[ "$(cat "$GHE_DATA_DIR/current/ssl-ca-certificates.tar")" = "fake ghe-export-ssl-ca-certificates data" ]
338347
fi
339348

340349
# verify that ghe-backup wrote its version information to the host

test/test-ghe-restore.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ echo "fake ghe-export-es-indices data" > "$GHE_DATA_DIR/current/elasticsearch.ta
7979
echo "fake ghe-export-ssh-host-keys data" > "$GHE_DATA_DIR/current/ssh-host-keys.tar"
8080
echo "fake ghe-export-repositories data" > "$GHE_DATA_DIR/current/repositories.tar"
8181
echo "fake ghe-export-settings data" > "$GHE_DATA_DIR/current/settings.json"
82+
echo "fake ghe-export-ssl-ca-certificates data" > "$GHE_DATA_DIR/current/ssl-ca-certificates.tar"
8283
echo "fake license data" > "$GHE_DATA_DIR/current/enterprise.ghl"
8384
echo "fake manage password hash data" > "$GHE_DATA_DIR/current/manage-password"
8485
echo "rsync" > "$GHE_DATA_DIR/current/strategy"
@@ -288,6 +289,9 @@ begin_test "ghe-restore -c into unconfigured vm"
288289

289290
# verify the UUID was transferred
290291
diff -ru "$GHE_DATA_DIR/current/uuid" "$GHE_REMOTE_DATA_USER_DIR/common/uuid"
292+
293+
# verify ghe-export-ssl-ca-certificates was run
294+
grep -q "fake ghe-export-ssl-ca-certificates data" "$TRASHDIR/restore-out"
291295
fi
292296
)
293297
end_test
@@ -356,6 +360,9 @@ begin_test "ghe-restore into unconfigured vm"
356360
# verify the UUID was transferred
357361
diff -ru "$GHE_DATA_DIR/current/uuid" "$GHE_REMOTE_DATA_USER_DIR/common/uuid"
358362

363+
# verify ghe-export-ssl-ca-certificates was run
364+
grep -q "fake ghe-export-ssl-ca-certificates data" "$TRASHDIR/restore-out"
365+
359366
# verify no config run after restore on unconfigured instance
360367
! grep -q "ghe-config-apply OK" "$TRASHDIR/restore-out"
361368
fi

0 commit comments

Comments
 (0)