@@ -36,66 +36,70 @@ if is_service_external 'mysql' "$snapshot_dir/settings.json"; then
36
36
echo " Error: EXTERNAL_DATABASE_RESTORE_SCRIPT is not configured. Please configure in backup.config."
37
37
exit 1
38
38
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
60
44
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
66
54
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 }
69
61
fi
70
62
else
71
- IMPORT_MYSQL=" unpigz | ghe-import-mysql-mysqldump"
72
- GHE_RESTORE_HOST=$GHE_HOSTNAME
63
+ ghe_mysql_master=$GHE_HOSTNAME
73
64
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
79
71
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
83
74
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
84
88
fi
89
+ fi
85
90
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
90
95
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
92
97
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"
95
100
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
100
104
101
105
bm_end " $( basename $0 ) "
0 commit comments