Skip to content

Commit bddc682

Browse files
authored
Merge pull request #272 from github/fix-2.8-restores
Backup and restore the appliance UUID
2 parents 8987607 + b7e4405 commit bddc682

File tree

4 files changed

+78
-9
lines changed

4 files changed

+78
-9
lines changed

bin/ghe-restore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ if ! $cluster; then
238238
fi
239239
fi
240240

241+
# Restore UUID if present and not restoring to cluster.
242+
if [ -s "$GHE_RESTORE_SNAPSHOT_PATH/uuid" ] && ! $cluster; then
243+
echo "Restoring UUID ..."
244+
cat "$GHE_RESTORE_SNAPSHOT_PATH/uuid" |
245+
ghe-ssh "$GHE_HOSTNAME" -- "sudo dd of='$GHE_REMOTE_DATA_USER_DIR/common/uuid' 2>/dev/null"
246+
fi
247+
241248
echo "Restoring MySQL database ..."
242249
bm_start "ghe-import-mysql"
243250
gzip -dc "$GHE_RESTORE_SNAPSHOT_PATH/mysql.sql.gz" | ghe-ssh "$GHE_HOSTNAME" -- 'ghe-import-mysql'

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ if [ "$GHE_BACKUP_STRATEGY" = "cluster" ]; then
5151
echo "Error: Enterprise Cluster is not configured yet, backup will fail" >&2
5252
exit 1
5353
fi
54+
else
55+
if ghe-ssh "$host" -- "sudo cat $GHE_REMOTE_DATA_USER_DIR/common/uuid 2>/dev/null" > uuid; then
56+
echo "* Transferring UUID ..." 1>&3
57+
fi
5458
fi
5559

5660
bm_end "$(basename $0)"

test/test-ghe-backup.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
4646

4747
mkdir -p "$GHE_REMOTE_DATA_USER_DIR/alambic_assets/github-enterprise-releases/0001"
4848
touch "$GHE_REMOTE_DATA_USER_DIR/alambic_assets/github-enterprise-releases/0001/1ed78298-522b-11e3-9dc0-22eed1f8132d"
49+
50+
# Create a fake UUID
51+
echo "fake uuid" > "$GHE_REMOTE_DATA_USER_DIR/common/uuid"
4952
fi
5053

5154
# Create some fake elasticsearch data in the remote data directory
@@ -130,9 +133,7 @@ begin_test "ghe-backup first snapshot"
130133
# verify manage-password file was backed up under v2.x VMs
131134
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
132135
[ "$(cat "$GHE_DATA_DIR/current/manage-password")" = "fake password hash data" ]
133-
fi
134136

135-
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
136137
# verify all hookshot user data was transferred
137138
diff -ru "$GHE_REMOTE_DATA_USER_DIR/hookshot" "$GHE_DATA_DIR/current/hookshot"
138139

@@ -147,6 +148,9 @@ begin_test "ghe-backup first snapshot"
147148

148149
# verify all alambic assets user data was transferred
149150
diff -ru "$GHE_REMOTE_DATA_USER_DIR/alambic_assets" "$GHE_DATA_DIR/current/alambic_assets"
151+
152+
# verify the UUID was transferred
153+
diff -ru "$GHE_REMOTE_DATA_USER_DIR/common/uuid" "$GHE_DATA_DIR/current/uuid"
150154
fi
151155

152156
# verify that ghe-backup wrote its version information to the host
@@ -213,9 +217,7 @@ begin_test "ghe-backup subsequent snapshot"
213217
# verify manage-password file was backed up under v2.x VMs
214218
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
215219
[ "$(cat "$GHE_DATA_DIR/current/manage-password")" = "fake password hash data" ]
216-
fi
217220

218-
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
219221
# verify all hookshot user data was transferred
220222
diff -ru "$GHE_REMOTE_DATA_USER_DIR/hookshot" "$GHE_DATA_DIR/current/hookshot"
221223

@@ -230,6 +232,9 @@ begin_test "ghe-backup subsequent snapshot"
230232

231233
# verify all alambic assets user data was transferred
232234
diff -ru "$GHE_REMOTE_DATA_USER_DIR/alambic_assets" "$GHE_DATA_DIR/current/alambic_assets"
235+
236+
# verify the UUID was transferred
237+
diff -ru "$GHE_REMOTE_DATA_USER_DIR/common/uuid" "$GHE_DATA_DIR/current/uuid"
233238
fi
234239
)
235240
end_test
@@ -312,9 +317,7 @@ begin_test "ghe-backup with relative data dir path"
312317
# verify manage-password file was backed up under v2.x VMs
313318
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
314319
[ "$(cat "$GHE_DATA_DIR/current/manage-password")" = "fake password hash data" ]
315-
fi
316320

317-
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
318321
# verify all hookshot user data was transferred
319322
diff -ru "$GHE_REMOTE_DATA_USER_DIR/hookshot" "$GHE_DATA_DIR/current/hookshot"
320323

@@ -329,6 +332,9 @@ begin_test "ghe-backup with relative data dir path"
329332

330333
# verify all alambic assets user data was transferred
331334
diff -ru "$GHE_REMOTE_DATA_USER_DIR/alambic_assets" "$GHE_DATA_DIR/current/alambic_assets"
335+
336+
# verify the UUID was transferred
337+
diff -ru "$GHE_REMOTE_DATA_USER_DIR/common/uuid" "$GHE_DATA_DIR/current/uuid"
332338
fi
333339

334340
# verify that ghe-backup wrote its version information to the host
@@ -459,8 +465,8 @@ end_test
459465

460466
begin_test "ghe-backup with leaked SSH host key detection for current backup"
461467
(
462-
set -e
463-
468+
set -e
469+
464470
SHARED_UTILS_PATH=$(dirname $(which ghe-detect-leaked-ssh-keys))
465471
# Inject the fingerprint into the blacklist
466472
echo 98:d8:99:d3:be:c0:55:05:db:b0:53:2f:1f:ad:b3:60 >> "$SHARED_UTILS_PATH/ghe-ssh-leaked-host-keys-list.txt"

test/test-ghe-restore.sh

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ mkdir -p gh-enterprise-es/node/0
1919
touch gh-enterprise-es/node/0/stuff1
2020
touch gh-enterprise-es/node/0/stuff2
2121

22-
# Create some fake hookshot data in the remote data directory
2322
if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
23+
# Create some fake hookshot data in the remote data directory
2424
mkdir -p "$GHE_DATA_DIR/1/hookshot"
2525
cd "$GHE_DATA_DIR/1/hookshot"
2626
mkdir -p repository-123 repository-456
@@ -50,6 +50,9 @@ if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
5050

5151
mkdir -p "$GHE_DATA_DIR/1/alambic_assets/github-enterprise-releases/0001"
5252
touch "$GHE_DATA_DIR/1/alambic_assets/github-enterprise-releases/0001/1ed78298-522b-11e3-9dc0-22eed1f8132d"
53+
54+
# Create a fake uuid
55+
echo "fake uuid" > "$GHE_DATA_DIR/1/uuid"
5356
fi
5457

5558
# Add some fake repositories to the snapshot
@@ -145,6 +148,9 @@ begin_test "ghe-restore into configured vm"
145148

146149
# verify all alambic assets user data was transferred
147150
diff -ru "$GHE_DATA_DIR/current/alambic_assets" "$GHE_REMOTE_DATA_USER_DIR/alambic_assets"
151+
152+
# verify the UUID was transferred
153+
diff -ru "$GHE_DATA_DIR/current/uuid" "$GHE_REMOTE_DATA_USER_DIR/common/uuid"
148154
fi
149155
)
150156
end_test
@@ -279,6 +285,9 @@ begin_test "ghe-restore -c into unconfigured vm"
279285

280286
# verify all alambic assets user data was transferred
281287
diff -ru "$GHE_DATA_DIR/current/alambic_assets" "$GHE_REMOTE_DATA_USER_DIR/alambic_assets"
288+
289+
# verify the UUID was transferred
290+
diff -ru "$GHE_DATA_DIR/current/uuid" "$GHE_REMOTE_DATA_USER_DIR/common/uuid"
282291
fi
283292
)
284293
end_test
@@ -344,6 +353,9 @@ begin_test "ghe-restore into unconfigured vm"
344353
# verify all alambic assets user data was transferred
345354
diff -ru "$GHE_DATA_DIR/current/alambic_assets" "$GHE_REMOTE_DATA_USER_DIR/alambic_assets"
346355

356+
# verify the UUID was transferred
357+
diff -ru "$GHE_DATA_DIR/current/uuid" "$GHE_REMOTE_DATA_USER_DIR/common/uuid"
358+
347359
# verify no config run after restore on unconfigured instance
348360
! grep -q "ghe-config-apply OK" "$TRASHDIR/restore-out"
349361
fi
@@ -396,6 +408,9 @@ begin_test "ghe-restore with host arg"
396408

397409
# verify all alambic assets user data was transferred
398410
diff -ru "$GHE_DATA_DIR/current/alambic_assets" "$GHE_REMOTE_DATA_USER_DIR/alambic_assets"
411+
412+
# verify the UUID was transferred
413+
diff -ru "$GHE_DATA_DIR/current/uuid" "$GHE_REMOTE_DATA_USER_DIR/common/uuid"
399414
fi
400415
)
401416
end_test
@@ -485,6 +500,43 @@ begin_test "ghe-restore with tarball strategy"
485500
)
486501
end_test
487502

503+
begin_test "ghe-restore with empty uuid file"
504+
(
505+
set -e
506+
507+
# Remove the UUID from the remote instance
508+
rm -f "$GHE_REMOTE_DATA_USER_DIR/common/uuid"
509+
510+
# Zero-length the UUID file
511+
cat /dev/null > "$GHE_DATA_DIR/current/uuid"
512+
513+
# Run a restore
514+
ghe-restore -v -f localhost
515+
516+
# Verify no uuid is restored
517+
[ ! -f "$GHE_REMOTE_DATA_USER_DIR/common/uuid" ]
518+
519+
)
520+
end_test
521+
522+
begin_test "ghe-restore with no uuid file"
523+
( set -e
524+
525+
# Remove the UUID from the remote instance
526+
rm -f "$GHE_REMOTE_DATA_USER_DIR/common/uuid"
527+
528+
# Remove the UUID file
529+
rm -f "$GHE_DATA_DIR/current/uuid"
530+
531+
# Run a restore
532+
ghe-restore -v -f localhost
533+
534+
# Verify no uuid is restored
535+
[ ! -f "$GHE_REMOTE_DATA_USER_DIR/common/uuid" ]
536+
537+
)
538+
end_test
539+
488540
begin_test "ghe-restore cluster backup to non-cluster appliance"
489541
(
490542
set -e

0 commit comments

Comments
 (0)