Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
Use sentinel file to identify type of mysql backup
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghao0718 committed Dec 16, 2019
1 parent 2c47acb commit ac15b30
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
8 changes: 8 additions & 0 deletions bin/ghe-backup
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..."
Expand Down
3 changes: 2 additions & 1 deletion share/github-backup-utils/ghe-restore-audit-log
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
23 changes: 21 additions & 2 deletions share/github-backup-utils/ghe-restore-mysql
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

0 comments on commit ac15b30

Please sign in to comment.