From ac15b307d01bd0377c5c646d5cf8eea609608cdb Mon Sep 17 00:00:00 2001 From: Hao Jiang Date: Mon, 16 Dec 2019 12:07:25 -0800 Subject: [PATCH] Use sentinel file to identify type of mysql backup --- bin/ghe-backup | 8 +++++++ .../github-backup-utils/ghe-restore-audit-log | 3 ++- share/github-backup-utils/ghe-restore-mysql | 23 +++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/bin/ghe-backup b/bin/ghe-backup index 3abe96749..11c4f3308 100755 --- a/bin/ghe-backup +++ b/bin/ghe-backup @@ -174,10 +174,18 @@ ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-ssh-host-keys' > ssh-host-keys.tar || failures="$failures ssh-host-keys" bm_end "ghe-export-ssh-host-keys" +# if we are going to take a binary backup +is_binary_backup(){ + ghe-ssh "$GHE_HOSTNAME" ghe-config --true "mysql.backup.binary" +} + echo "Backing up MySQL database ..." bm_start "ghe-export-mysql" echo 'set -o pipefail; ghe-export-mysql | gzip' | ghe-ssh "$GHE_HOSTNAME" -- /bin/bash > mysql.sql.gz || failures="$failures mysql" +if is_binary_backup; then + touch mysql-binary-backup-sentinel +fi bm_end "ghe-export-mysql" echo "Backing up Redis database ..." diff --git a/share/github-backup-utils/ghe-restore-audit-log b/share/github-backup-utils/ghe-restore-audit-log index 3e4622059..75fe0d419 100755 --- a/share/github-backup-utils/ghe-restore-audit-log +++ b/share/github-backup-utils/ghe-restore-audit-log @@ -46,8 +46,9 @@ is_mysql_supported(){ 'test \"\$ENTERPRISE_AUDIT_LOG_MYSQL_LOGGER_ENABLED\" = \"1\""' | ghe-ssh "$GHE_HOSTNAME" -- /bin/bash } +# Check if the backup is binary by looking up the sentinel file is_binary_backup(){ - ghe-ssh "$GHE_HOSTNAME" ghe-config --true "mysql.backup.binary" + test -f "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT"/mysql-binary-backup-sentinel } # Helper function to set remote flags in `/data/user/common/audit-log-import` diff --git a/share/github-backup-utils/ghe-restore-mysql b/share/github-backup-utils/ghe-restore-mysql index 9f1ed3c8a..e661e78e6 100755 --- a/share/github-backup-utils/ghe-restore-mysql +++ b/share/github-backup-utils/ghe-restore-mysql @@ -33,13 +33,32 @@ cleanup() { } trap 'cleanup' INT TERM EXIT +# Check if the backup is binary by looking up the sentinel file +is_binary_backup(){ + test -f $snapshot_dir/mysql-binary-backup-sentinel +} + +# if mysql.backup.binary feature flag is on +is_binary_backup_feature_on(){ + ghe-ssh "$GHE_HOSTNAME" ghe-config --true "mysql.backup.binary" +} + +if is_binary_backup; then + if ! is_binary_backup_feature_on; then + echo "To restore from a binary backup, you have to set ghe-config \"mysql.backup.binary\" to true" >&2 + exit 2 + fi + IMPORT_MYSQL=ghe-import-mysql-xtrabackup +else + IMPORT_MYSQL=ghe-import-mysql-mysqldump +fi + ghe-ssh "$GHE_HOSTNAME" -- "sudo mkdir -p '$GHE_REMOTE_DATA_USER_DIR/tmp'" 1>&3 # Transfer MySQL data from the snapshot to the GitHub instance. 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" # Import the database -echo "gunzip -cd $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz | ghe-import-mysql" | ghe-ssh "$GHE_HOSTNAME" -- /bin/bash 1>&3 - +echo "gunzip -cd $GHE_REMOTE_DATA_USER_DIR/tmp/mysql.sql.gz | $IMPORT_MYSQL" | ghe-ssh "$GHE_HOSTNAME" -- /bin/bash 1>&3 bm_end "$(basename $0)"