Skip to content

Commit 2bca229

Browse files
committed
Merge pull request #201 from github/backup-utils-2.6
Bump version: 2.6.0
2 parents bf299f2 + 2342bc9 commit 2bca229

File tree

9 files changed

+229
-2
lines changed

9 files changed

+229
-2
lines changed

bin/ghe-backup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
173173
echo "Backing up asset attachments ..."
174174
ghe-backup-alambic-cluster ||
175175
failures="$failures alambic_assets"
176+
177+
echo "Backing up custom Git hooks ..."
178+
ghe-backup-git-hooks-cluster ||
179+
failures="$failures alambic_assets"
176180
else
177181
echo "Backing up asset attachments ..."
178182
ghe-backup-userdata alambic_assets ||
@@ -185,6 +189,10 @@ if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
185189
echo "Backing up hook deliveries ..."
186190
ghe-backup-userdata hookshot ||
187191
failures="$failures hookshot"
192+
193+
echo "Backing up custom Git hooks ..."
194+
ghe-backup-userdata git-hooks ||
195+
failures="$failures git-hooks"
188196
fi
189197
fi
190198

bin/ghe-restore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ ghe-ssh "$GHE_HOSTNAME" -- 'ghe-import-authorized-keys' < "$GHE_RESTORE_SNAPSHOT
241241
if $cluster; then
242242
echo "Restoring storage data ..."
243243
ghe-restore-alambic-cluster "$GHE_HOSTNAME" 1>&3
244+
ghe-restore-git-hooks-cluster "$GHE_HOSTNAME" 1>&3
244245
elif [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
245246
echo "Restoring asset attachments ..."
246247
ghe-restore-userdata alambic_assets "$GHE_HOSTNAME" 1>&3
@@ -250,6 +251,9 @@ elif [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
250251

251252
echo "Restoring hook deliveries ..."
252253
ghe-restore-userdata hookshot "$GHE_HOSTNAME" 1>&3
254+
255+
echo "Restoring custom Git hooks ..."
256+
ghe-restore-userdata git-hooks "$GHE_HOSTNAME" 1>&3
253257
fi
254258

255259
if $cluster; then

debian/changelog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
github-backup-utils (2.6.0) UNRELEASED; urgency=medium
2+
3+
* Adds support for GitHub Enterprise 2.6
4+
* Adds an extra supported location for the backup configuration #197
5+
* New config option to check for corrupted repositories after the backup #195
6+
* General improvements and bug fixes
7+
8+
-- Sergio Rubio <[email protected]> Tue, 26 Apr 2016 18:03:01 +0200
9+
110
github-backup-utils (2.5.2) UNRELEASED; urgency=medium
211

312
* New configuration variable: GHE_CREATE_DATA_DIR #186
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: ghe-backup-git-hooks-cluster
3+
#/ Take an online, incremental snapshot of custom Git hooks configuration.
4+
#/
5+
#/ Note: This command typically isn't called directly. It's invoked by
6+
#/ ghe-backup when the cluster strategy is used.
7+
set -e
8+
9+
# Bring in the backup configuration
10+
cd $(dirname "$0")/../..
11+
. share/github-backup-utils/ghe-backup-config
12+
13+
# Split host:port into parts
14+
port=$(ssh_port_part "$GHE_HOSTNAME")
15+
host=$(ssh_host_part "$GHE_HOSTNAME")
16+
17+
# Add user / -l option
18+
user="${host%@*}"
19+
[ "$user" = "$host" ] && user="admin"
20+
21+
backup_dir="$GHE_SNAPSHOT_DIR/git-hooks"
22+
23+
# Location of last good backup for rsync --link-dest
24+
backup_current="$GHE_DATA_DIR/current/git-hooks"
25+
26+
# Verify rsync is available.
27+
if ! rsync --version 1>/dev/null 2>&1; then
28+
echo "Error: rsync not found." 1>&2
29+
exit 1
30+
fi
31+
32+
# Perform a host-check and establish GHE_REMOTE_XXX variables.
33+
ghe_remote_version_required "$host"
34+
35+
# Generate SSH config for forwarding
36+
37+
config=""
38+
39+
# git server hostnames
40+
hostnames=$(ghe_cluster_online_nodes "git-server")
41+
for hostname in $hostnames; do
42+
config="$config
43+
Host $hostname
44+
ProxyCommand ssh -q $GHE_EXTRA_SSH_OPTS -p $port $user@$host nc.openbsd %h %p
45+
StrictHostKeyChecking=no
46+
"
47+
done
48+
49+
config_file=$(mktemp -t cluster-backup-restore-XXXXXX)
50+
echo "$config" > "$config_file"
51+
52+
opts="$GHE_EXTRA_SSH_OPTS -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PasswordAuthentication=no"
53+
54+
# Removes the remote sync-in-progress file on exit, re-enabling GC operations
55+
# on the remote instance.
56+
cleanup() {
57+
rm -f $config_file
58+
}
59+
trap 'cleanup' EXIT
60+
trap 'exit $?' INT # ^C always terminate
61+
62+
# If we have a previous increment, avoid transferring existing files via rsync's
63+
# --link-dest support. This also decreases physical space usage considerably.
64+
if [ -d "$backup_current" ]; then
65+
link_dest="--link-dest=../../current/git-hooks"
66+
fi
67+
68+
# Transfer Git hooks data from a GitHub instance to the current snapshot
69+
# directory, using a previous snapshot to avoid transferring files that have
70+
# already been transferred. A set of rsync filter rules are provided on stdin
71+
# for each invocation.
72+
rsync_git_hooks_data () {
73+
port=$(ssh_port_part "$1")
74+
host=$(ssh_host_part "$1")
75+
76+
shift
77+
ghe-rsync -a \
78+
-e "ssh -q $opts -p $port -F $config_file -l $user" $link_dest \
79+
--rsync-path='sudo -u git rsync' \
80+
"$host:$GHE_REMOTE_DATA_USER_DIR/git-hooks/" \
81+
"$backup_dir" 1>&3
82+
}
83+
84+
for hostname in $hostnames; do
85+
ghe-ssh -F $config_file "$hostname:122" -- "[ -d '$GHE_REMOTE_DATA_USER_DIR/git-hooks' ]" || exit 0
86+
# We can stop after the first successful sync since hooks are the same everywhere
87+
rsync_git_hooks_data $hostname:122 && break
88+
done
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: ghe-restore-git-hooks-cluster <host>
3+
#/ Restore custom Git hooks data from an rsync snapshot
4+
#/
5+
#/ Note: This command typically isn't called directly. It's invoked by
6+
#/ ghe-restore when the cluster strategy is used.
7+
set -e
8+
9+
# Bring in the backup configuration
10+
cd $(dirname "$0")/../..
11+
. share/github-backup-utils/ghe-backup-config
12+
13+
# Show usage and bail with no arguments
14+
[ -z "$*" ] && print_usage
15+
16+
# Grab host arg
17+
GHE_HOSTNAME="$1"
18+
19+
# Perform a host-check and establish GHE_REMOTE_XXX variables.
20+
ghe_remote_version_required "$GHE_HOSTNAME"
21+
22+
# The snapshot to restore should be set by the ghe-restore command but this lets
23+
# us run this script directly.
24+
: ${GHE_RESTORE_SNAPSHOT:=current}
25+
26+
# Generate SSH config for forwarding
27+
config=""
28+
29+
# Split host:port into parts
30+
port=$(ssh_port_part "$GHE_HOSTNAME")
31+
host=$(ssh_host_part "$GHE_HOSTNAME")
32+
33+
# Add user / -l option
34+
user="${host%@*}"
35+
[ "$user" = "$host" ] && user="admin"
36+
37+
hostnames=$(ghe_cluster_online_nodes "git-server")
38+
for hostname in $hostnames; do
39+
config="$config
40+
Host $hostname
41+
ServerAliveInterval 60
42+
ProxyCommand ssh -q $GHE_EXTRA_SSH_OPTS -p $port $user@$host nc.openbsd %h %p
43+
StrictHostKeyChecking=no
44+
"
45+
done
46+
47+
config_file=$(mktemp -t cluster-backup-restore-XXXXXX)
48+
echo "$config" > "$config_file"
49+
50+
opts="$GHE_EXTRA_SSH_OPTS -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PasswordAuthentication=no"
51+
52+
cleanup() {
53+
for pid in $(jobs -p); do
54+
kill -KILL $pid > /dev/null 2>&1 || true
55+
done
56+
rm -f $config_file
57+
}
58+
trap 'cleanup' INT TERM EXIT
59+
60+
if [ -d "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/git-hooks" ]; then
61+
for hostname in $hostnames; do
62+
ghe-rsync -aHR --delete \
63+
-e "ssh -q $opts -p $port -F $config_file -l $user" \
64+
--rsync-path="sudo -u git rsync" \
65+
"$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/git-hooks" \
66+
"$route:$GHE_REMOTE_DATA_USER_DIR/git-hooks" &
67+
done
68+
69+
for pid in $(jobs -p); do
70+
wait $pid
71+
ret_code=$?
72+
if [ "$ret_code" != "0" ]; then
73+
echo "$pid exited $ret_code"
74+
exit $ret_code
75+
fi
76+
done
77+
fi

share/github-backup-utils/ghe-restore-repositories-dgit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#/ Usage: ghe-restore-repositories-dgit <host>
3-
#/ Restore repositories fron an rsync snapshot of all Git repository data to a GitHub cluster.
3+
#/ Restore repositories from an rsync snapshot of all Git repository data to a GitHub cluster.
44
#/
55
#/ Note: This script typically isn't called directly. It's invoked by the
66
#/ ghe-restore command when restoring into a cluster.

share/github-backup-utils/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.5.2
1+
2.6.0

test/test-ghe-backup.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
2323
cd "$GHE_REMOTE_DATA_USER_DIR/hookshot"
2424
mkdir -p repository-123 repository-456
2525
touch repository-123/test.bpack repository-456/test.bpack
26+
27+
mkdir -p "$GHE_REMOTE_DATA_USER_DIR/git-hooks"
28+
cd "$GHE_REMOTE_DATA_USER_DIR/git-hooks"
29+
mkdir -p repository-123 repository-456
30+
touch repository-123/script.sh repository-456/foo.sh
2631
fi
2732

2833
# Create some fake alambic data in the remote data directory
@@ -122,6 +127,9 @@ begin_test "ghe-backup first snapshot"
122127
# verify all hookshot user data was transferred
123128
diff -ru "$GHE_REMOTE_DATA_USER_DIR/hookshot" "$GHE_DATA_DIR/current/hookshot"
124129

130+
# verify all git hooks data was transferred
131+
diff -ru "$GHE_REMOTE_DATA_USER_DIR/git-hooks" "$GHE_DATA_DIR/current/git-hooks"
132+
125133
# verify all alambic assets user data was transferred
126134
diff -ru "$GHE_REMOTE_DATA_USER_DIR/alambic_assets" "$GHE_DATA_DIR/current/alambic_assets"
127135
fi
@@ -197,6 +205,9 @@ begin_test "ghe-backup subsequent snapshot"
197205
# verify all hookshot user data was transferred
198206
diff -ru "$GHE_REMOTE_DATA_USER_DIR/hookshot" "$GHE_DATA_DIR/current/hookshot"
199207

208+
# verify all git hooks data was transferred
209+
diff -ru "$GHE_REMOTE_DATA_USER_DIR/git-hooks" "$GHE_DATA_DIR/current/git-hooks"
210+
200211
# verify all alambic assets user data was transferred
201212
diff -ru "$GHE_REMOTE_DATA_USER_DIR/alambic_assets" "$GHE_DATA_DIR/current/alambic_assets"
202213
fi
@@ -282,6 +293,19 @@ begin_test "ghe-backup empty hookshot directory"
282293
)
283294
end_test
284295

296+
begin_test "ghe-backup empty git-hooks directory"
297+
(
298+
set -e
299+
300+
rm -rf $GHE_REMOTE_DATA_USER_DIR/git-hooks/repository-*
301+
rm -rf $GHE_DATA_DIR/current/git-hooks/repository-*
302+
ghe-backup
303+
304+
# Check that the "--link-dest arg does not exist" message hasn't occurred.
305+
[ ! "$(grep "[l]ink-dest arg does not exist" $TRASHDIR/out)" ]
306+
)
307+
end_test
308+
285309
begin_test "ghe-backup fsck"
286310
(
287311
set -e

test/test-ghe-restore.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ if [ "$GHE_VERSION_MAJOR" -ge 2 ]; then
2525
cd "$GHE_DATA_DIR/1/hookshot"
2626
mkdir -p repository-123 repository-456
2727
touch repository-123/test.bpack repository-456/test.bpack
28+
29+
mkdir -p "$GHE_DATA_DIR/1/git-hooks"
30+
cd "$GHE_DATA_DIR/1/git-hooks"
31+
mkdir -p repository-123 repository-456
32+
touch repository-123/script.sh repository-456/foo.sh
2833
fi
2934

3035
# Create some fake alambic data in the remote data directory
@@ -122,6 +127,9 @@ begin_test "ghe-restore into configured vm"
122127
# verify all hookshot user data was transferred
123128
diff -ru "$GHE_DATA_DIR/current/hookshot" "$GHE_REMOTE_DATA_USER_DIR/hookshot"
124129

130+
# verify all git hooks data was transferred
131+
diff -ru "$GHE_DATA_DIR/current/git-hooks" "$GHE_REMOTE_DATA_USER_DIR/git-hooks"
132+
125133
# verify all alambic assets user data was transferred
126134
diff -ru "$GHE_DATA_DIR/current/alambic_assets" "$GHE_REMOTE_DATA_USER_DIR/alambic_assets"
127135
fi
@@ -240,6 +248,9 @@ begin_test "ghe-restore -c into unconfigured vm"
240248
# verify all hookshot user data was transferred
241249
diff -ru "$GHE_DATA_DIR/current/hookshot" "$GHE_REMOTE_DATA_USER_DIR/hookshot"
242250

251+
# verify all git hooks data was transferred
252+
diff -ru "$GHE_DATA_DIR/current/git-hooks" "$GHE_REMOTE_DATA_USER_DIR/git-hooks"
253+
243254
# verify all alambic assets user data was transferred
244255
diff -ru "$GHE_DATA_DIR/current/alambic_assets" "$GHE_REMOTE_DATA_USER_DIR/alambic_assets"
245256
fi
@@ -299,6 +310,9 @@ begin_test "ghe-restore into unconfigured vm"
299310
# verify all hookshot user data was transferred
300311
diff -ru "$GHE_DATA_DIR/current/hookshot" "$GHE_REMOTE_DATA_USER_DIR/hookshot"
301312

313+
# verify all git hooks data was transferred
314+
diff -ru "$GHE_DATA_DIR/current/git-hooks" "$GHE_REMOTE_DATA_USER_DIR/git-hooks"
315+
302316
# verify all alambic assets user data was transferred
303317
diff -ru "$GHE_DATA_DIR/current/alambic_assets" "$GHE_REMOTE_DATA_USER_DIR/alambic_assets"
304318

@@ -348,6 +362,9 @@ begin_test "ghe-restore with host arg"
348362
# verify all hookshot user data was transferred
349363
diff -ru "$GHE_DATA_DIR/current/hookshot" "$GHE_REMOTE_DATA_USER_DIR/hookshot"
350364

365+
# verify all git hooks data was transferred
366+
diff -ru "$GHE_DATA_DIR/current/git-hooks" "$GHE_REMOTE_DATA_USER_DIR/git-hooks"
367+
351368
# verify all alambic assets user data was transferred
352369
diff -ru "$GHE_DATA_DIR/current/alambic_assets" "$GHE_REMOTE_DATA_USER_DIR/alambic_assets"
353370
fi

0 commit comments

Comments
 (0)