Skip to content

Commit 5d92693

Browse files
committed
A few minor edits
1 parent 6cb2b67 commit 5d92693

File tree

3 files changed

+55
-51
lines changed

3 files changed

+55
-51
lines changed

backup.config-example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ GHE_NUM_SNAPSHOTS=10
8484

8585
# When running an external mysql database, run this script to trigger a MySQL restore
8686
# rather than attempting to backup via backup-utils directly.
87-
#EXTERNAL_DATABASE_RESTORE_SCRIPT="/bin/false"
87+
#EXTERNAL_DATABASE_RESTORE_SCRIPT="/bin/false"

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

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -36,66 +36,70 @@ if is_service_external 'mysql' "$snapshot_dir/settings.json"; then
3636
echo "Error: EXTERNAL_DATABASE_RESTORE_SCRIPT is not configured. Please configure in backup.config."
3737
exit 1
3838
fi
39-
else
40-
ssh_config_file_opt=
41-
if is_binary_backup_feature_on; then
42-
# Feature "mysql.backup.binary" is on, which means new backup scripts are available
43-
if is_binary_backup "$snapshot_dir"; then
44-
if $CLUSTER ; then
45-
ghe_mysql_master=$(ghe-ssh "$GHE_HOSTNAME" ghe-config "cluster.mysql-master")
46-
if [ -z $ghe_mysql_master ]; then
47-
echo "Something is wrong with configuration: cluster.mysql-master not found" >&2
48-
exit 2
49-
else
50-
tempdir=$(mktemp -d -t backup-utils-restore-XXXXXX)
51-
ssh_config_file="$tempdir/ssh_config"
52-
ssh_config_file_opt="-F $ssh_config_file"
53-
ghe-ssh-config "$GHE_HOSTNAME" "$ghe_mysql_master" > "$ssh_config_file"
54-
port=$(ssh_port_part "$GHE_HOSTNAME")
55-
ghe_mysql_master=$ghe_mysql_master${port:+:$port}
56-
fi
57-
else
58-
ghe_mysql_master=$GHE_HOSTNAME
59-
fi
39+
# Finsh the benchmark and exit early. If the script returns a non-zero
40+
# exit code, it will be caught by`set -e`
41+
bm_end "$(basename $0)"
42+
exit 0
43+
fi
6044

61-
# Check if the decompress needed by looking into the sentinel file
62-
# In 2.19.5 we compress the binary backup twice
63-
if [ "$(cat $snapshot_dir/mysql-binary-backup-sentinel)" = "NO_ADDITIONAL_COMPRESSION" ]; then
64-
IMPORT_MYSQL=ghe-import-mysql-xtrabackup
65-
GHE_RESTORE_HOST=$ghe_mysql_master
45+
ssh_config_file_opt=
46+
if is_binary_backup_feature_on; then
47+
# Feature "mysql.backup.binary" is on, which means new backup scripts are available
48+
if is_binary_backup "$snapshot_dir"; then
49+
if $CLUSTER ; then
50+
ghe_mysql_master=$(ghe-ssh "$GHE_HOSTNAME" ghe-config "cluster.mysql-master")
51+
if [ -z $ghe_mysql_master ]; then
52+
echo "Something is wrong with configuration: cluster.mysql-master not found" >&2
53+
exit 2
6654
else
67-
IMPORT_MYSQL="unpigz | ghe-import-mysql-xtrabackup"
68-
GHE_RESTORE_HOST=$ghe_mysql_master
55+
tempdir=$(mktemp -d -t backup-utils-restore-XXXXXX)
56+
ssh_config_file="$tempdir/ssh_config"
57+
ssh_config_file_opt="-F $ssh_config_file"
58+
ghe-ssh-config "$GHE_HOSTNAME" "$ghe_mysql_master" > "$ssh_config_file"
59+
port=$(ssh_port_part "$GHE_HOSTNAME")
60+
ghe_mysql_master=$ghe_mysql_master${port:+:$port}
6961
fi
7062
else
71-
IMPORT_MYSQL="unpigz | ghe-import-mysql-mysqldump"
72-
GHE_RESTORE_HOST=$GHE_HOSTNAME
63+
ghe_mysql_master=$GHE_HOSTNAME
7364
fi
74-
else
75-
# We do not allow to restore binary backup without "mysql.backup.binary" set
76-
if is_binary_backup "$snapshot_dir"; then
77-
echo "To restore from a binary backup, you have to set ghe-config \"mysql.backup.binary\" to true" >&2
78-
exit 2
65+
66+
# Check if the decompress needed by looking into the sentinel file
67+
# In 2.19.5 we compress the binary backup twice
68+
if [ "$(cat $snapshot_dir/mysql-binary-backup-sentinel)" = "NO_ADDITIONAL_COMPRESSION" ]; then
69+
IMPORT_MYSQL=ghe-import-mysql-xtrabackup
70+
GHE_RESTORE_HOST=$ghe_mysql_master
7971
else
80-
# legacy mode
81-
IMPORT_MYSQL="unpigz | ghe-import-mysql"
82-
GHE_RESTORE_HOST=$GHE_HOSTNAME
72+
IMPORT_MYSQL="unpigz | ghe-import-mysql-xtrabackup"
73+
GHE_RESTORE_HOST=$ghe_mysql_master
8374
fi
75+
else
76+
IMPORT_MYSQL="unpigz | ghe-import-mysql-mysqldump"
77+
GHE_RESTORE_HOST=$GHE_HOSTNAME
78+
fi
79+
else
80+
# We do not allow to restore binary backup without "mysql.backup.binary" set
81+
if is_binary_backup "$snapshot_dir"; then
82+
echo "To restore from a binary backup, you have to set ghe-config \"mysql.backup.binary\" to true" >&2
83+
exit 2
84+
else
85+
# legacy mode
86+
IMPORT_MYSQL="unpigz | ghe-import-mysql"
87+
GHE_RESTORE_HOST=$GHE_HOSTNAME
8488
fi
89+
fi
8590

86-
cleanup() {
87-
ghe-ssh $ssh_config_file_opt "$GHE_RESTORE_HOST" -- "sudo rm -rf $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz"
88-
}
89-
trap 'cleanup' INT TERM EXIT
91+
cleanup() {
92+
ghe-ssh $ssh_config_file_opt "$GHE_RESTORE_HOST" -- "sudo rm -rf $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz"
93+
}
94+
trap 'cleanup' INT TERM EXIT
9095

91-
ghe-ssh $ssh_config_file_opt "$GHE_RESTORE_HOST" -- "sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR/tmp'" 1>&3
96+
ghe-ssh $ssh_config_file_opt "$GHE_RESTORE_HOST" -- "sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR/tmp'" 1>&3
9297

93-
# Transfer MySQL data from the snapshot to the GitHub instance.
94-
cat $snapshot_dir/mysql.sql.gz | ghe-ssh $ssh_config_file_opt "$GHE_RESTORE_HOST" -- "sudo dd of=$GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz >/dev/null 2>&1"
98+
# Transfer MySQL data from the snapshot to the GitHub instance.
99+
cat $snapshot_dir/mysql.sql.gz | ghe-ssh $ssh_config_file_opt "$GHE_RESTORE_HOST" -- "sudo dd of=$GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz >/dev/null 2>&1"
95100

96-
echo "Restore MySQL database ..."
97-
# Import the database
98-
echo "cat $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz | $IMPORT_MYSQL" | ghe-ssh $ssh_config_file_opt "$GHE_RESTORE_HOST" -- /bin/bash 1>&3
99-
fi
101+
echo "Restore MySQL database ..."
102+
# Import the database
103+
echo "cat $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz | $IMPORT_MYSQL" | ghe-ssh $ssh_config_file_opt "$GHE_RESTORE_HOST" -- /bin/bash 1>&3
100104

101105
bm_end "$(basename $0)"

test/test-ghe-backup-config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,4 @@ begin_test "ghe-backup-config is_service_external unknown service"
224224

225225
! is_service_external 'hubot' $tmpfile
226226
)
227-
end_test
227+
end_test

0 commit comments

Comments
 (0)