Skip to content

Commit fb84bd6

Browse files
authored
Merge pull request #551 from github/oakeyc/update-binary
Oakeyc/update binary
2 parents 313d490 + 8283873 commit fb84bd6

File tree

6 files changed

+92
-7
lines changed

6 files changed

+92
-7
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ matrix:
1010
- brew install shellcheck
1111
- brew install jq
1212
- brew install coreutils
13+
- brew install pigz
1314
script: make test
1415
- os: linux
1516
dist: trusty
@@ -26,4 +27,5 @@ matrix:
2627
- fakeroot
2728
- jq
2829
- coreutils
30+
- pigz
2931
script: debuild -uc -us

bin/ghe-backup

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,25 @@ if [ "$(ls -il dest1/testfile | awk '{ print $1 }')" != "$(ls -il dest2/testfile
8181
fi
8282
rm -rf src dest1 dest2
8383

84+
# if we should use gitbackups to backup repositories
85+
should_use_gitbackups_for_repositories(){
86+
ghe-ssh "$GHE_HOSTNAME" ghe-config --true "app.github.gitbackups"
87+
}
88+
89+
# check that the appliance supports using gitbackups for repositories
90+
can_use_gitbackups_for_repositories(){
91+
ghe-ssh "$GHE_HOSTNAME" test -e /data/github/current/bin/ghe-backup-repositories
92+
}
93+
94+
# Exit early if the appliance is missing script to backup repositories using gitbackups
95+
if should_use_gitbackups_for_repositories; then
96+
if ! can_use_gitbackups_for_repositories; then
97+
echo "Error: Configuration setting 'app.github.gitbackups' is enabled but this version of GHES cannot use gitbackups to back up repositories via 'ghe-backup'."
98+
echo "Disable configuration setting 'app.github.gitbackups' and re-run 'ghe-backup' to use rsync."
99+
exit 1
100+
fi
101+
fi
102+
84103
# To prevent multiple backup runs happening at the same time, we create a
85104
# in-progress file with the timestamp and pid of the backup process,
86105
# giving us a form of locking.
@@ -174,10 +193,23 @@ ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-ssh-host-keys' > ssh-host-keys.tar ||
174193
failures="$failures ssh-host-keys"
175194
bm_end "ghe-export-ssh-host-keys"
176195

196+
# if we are going to take a binary backup
197+
is_binary_backup(){
198+
ghe-ssh "$GHE_HOSTNAME" ghe-config --true "mysql.backup.binary"
199+
}
200+
177201
echo "Backing up MySQL database ..."
178202
bm_start "ghe-export-mysql"
179-
echo 'set -o pipefail; ghe-export-mysql | gzip' |
203+
export_command="ghe-export-mysql"
204+
if ! is_binary_backup; then
205+
# binary backup is already compressed
206+
export_command+=" | pigz"
207+
fi
208+
echo "set -o pipefail; $export_command" |
180209
ghe-ssh "$GHE_HOSTNAME" -- /bin/bash > mysql.sql.gz || failures="$failures mysql"
210+
if is_binary_backup; then
211+
echo "NO_ADDITIONAL_COMPRESSION" > mysql-binary-backup-sentinel
212+
fi
181213
bm_end "ghe-export-mysql"
182214

183215
echo "Backing up Redis database ..."

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

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,67 @@ ghe_remote_version_required "$GHE_HOSTNAME"
2828
# The directory holding the snapshot to restore
2929
snapshot_dir="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT"
3030

31+
# Check if the backup is binary by looking up the sentinel file
32+
is_binary_backup(){
33+
test -f $snapshot_dir/mysql-binary-backup-sentinel
34+
}
35+
36+
# if mysql.backup.binary feature flag is on
37+
is_binary_backup_feature_on(){
38+
ghe-ssh "$GHE_HOSTNAME" ghe-config --true "mysql.backup.binary"
39+
}
40+
41+
if ghe-ssh "$GHE_HOSTNAME" test -f /etc/github/cluster ; then
42+
ghe_mysql_master=$(ghe-ssh "$GHE_HOSTNAME" ghe-config "cluster.mysql-master")
43+
if [ -z $ghe_mysql_master ]; then
44+
ghe_mysql_master=$GHE_HOSTNAME
45+
else
46+
port=$(ssh_port_part "$GHE_HOSTNAME")
47+
ghe_mysql_master=$ghe_mysql_master${port:+:$port}
48+
fi
49+
else
50+
ghe_mysql_master=$GHE_HOSTNAME
51+
fi
52+
53+
if is_binary_backup_feature_on; then
54+
# Feature "mysql.backup.binary" is on, which means new backup scripts are available
55+
if is_binary_backup; then
56+
# Check if the decompress needed by looking into the sentinel file
57+
# In 2.19.5 we compress the binary backup twice
58+
if [ "$(cat $snapshot_dir/mysql-binary-backup-sentinel)" = "NO_ADDITIONAL_COMPRESSION" ]; then
59+
IMPORT_MYSQL=ghe-import-mysql-xtrabackup
60+
GHE_RESTORE_HOST=$ghe_mysql_master
61+
else
62+
IMPORT_MYSQL="unpigz | ghe-import-mysql-xtrabackup"
63+
GHE_RESTORE_HOST=$ghe_mysql_master
64+
fi
65+
else
66+
IMPORT_MYSQL="unpigz | ghe-import-mysql-mysqldump"
67+
GHE_RESTORE_HOST=$GHE_HOSTNAME
68+
fi
69+
else
70+
# We do not allow to restore binary backup without "mysql.backup.binary" set
71+
if is_binary_backup; then
72+
echo "To restore from a binary backup, you have to set ghe-config \"mysql.backup.binary\" to true" >&2
73+
exit 2
74+
else
75+
# legacy mode
76+
IMPORT_MYSQL="unpigz | ghe-import-mysql-mysqldump"
77+
GHE_RESTORE_HOST=$GHE_HOSTNAME
78+
fi
79+
fi
80+
3181
cleanup() {
32-
ghe-ssh "$GHE_HOSTNAME" -- "sudo rm -rf $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz"
82+
ghe-ssh "$GHE_RESTORE_HOST" -- "sudo rm -rf $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz"
3383
}
3484
trap 'cleanup' INT TERM EXIT
3585

36-
ghe-ssh "$GHE_HOSTNAME" -- "sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR/tmp'" 1>&3
86+
ghe-ssh "$GHE_RESTORE_HOST" -- "sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR/tmp'" 1>&3
3787

3888
# Transfer MySQL data from the snapshot to the GitHub instance.
39-
cat $snapshot_dir/mysql.sql.gz | ghe-ssh "$GHE_HOSTNAME" -- "sudo dd of=$GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz >/dev/null 2>&1"
89+
cat $snapshot_dir/mysql.sql.gz | ghe-ssh "$GHE_RESTORE_HOST" -- "sudo dd of=$GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz >/dev/null 2>&1"
4090

4191
# Import the database
42-
echo "gunzip -cd $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz | ghe-import-mysql" | ghe-ssh "$GHE_HOSTNAME" -- /bin/bash 1>&3
43-
92+
echo "cat $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz | $IMPORT_MYSQL" | ghe-ssh "$GHE_RESTORE_HOST" -- /bin/bash 1>&3
4493

4594
bm_end "$(basename $0)"

share/github-backup-utils/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.19.2
1+
2.19.3

test/bin/ghe-import-mysql-mysqldump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ghe-fake-import-command

test/bin/ghe-import-mysql-xtrabackup

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ghe-fake-import-command

0 commit comments

Comments
 (0)