From e73dcc3659396e1c870d50eb1cebbc8fac8048c1 Mon Sep 17 00:00:00 2001 From: Caine Jette Date: Wed, 13 May 2020 18:12:08 -0700 Subject: [PATCH 1/7] Echo MySQL backup strategy --- bin/ghe-backup | 6 +++++- share/github-backup-utils/ghe-backup-config | 4 ++++ share/github-backup-utils/ghe-backup-mysql | 5 ----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bin/ghe-backup b/bin/ghe-backup index e45817727..e86f94ec5 100755 --- a/bin/ghe-backup +++ b/bin/ghe-backup @@ -180,7 +180,11 @@ 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" -echo "Backing up MySQL database ..." +if is_binary_backup_feature_on; then + echo "Backing up MySQL database using binary backup ..." +else + echo "Backing up MySQL database using logical backup ..." +fi ghe-backup-mysql || failures="$failures mysql" commands=(" diff --git a/share/github-backup-utils/ghe-backup-config b/share/github-backup-utils/ghe-backup-config index 8b0d1d4bf..493efa51b 100755 --- a/share/github-backup-utils/ghe-backup-config +++ b/share/github-backup-utils/ghe-backup-config @@ -381,3 +381,7 @@ fix_paths_for_ghe_version() { # GHES), then don't modify lines with "gist" in them. sed $GIST_FILTER -e 's/\/$//; s/^[^\/]*$/./; s/\/[^\/]*$//' } + +is_binary_backup_feature_on(){ + ghe-ssh "$GHE_HOSTNAME" ghe-config --true "mysql.backup.binary" +} diff --git a/share/github-backup-utils/ghe-backup-mysql b/share/github-backup-utils/ghe-backup-mysql index 983341461..6148fd2d5 100755 --- a/share/github-backup-utils/ghe-backup-mysql +++ b/share/github-backup-utils/ghe-backup-mysql @@ -15,11 +15,6 @@ bm_start "$(basename $0)" # Perform a host-check and establish the remote version in GHE_REMOTE_VERSION. ghe_remote_version_required "$GHE_HOSTNAME" -# if we are going to take a binary backup -is_binary_backup_feature_on(){ - ghe-ssh "$GHE_HOSTNAME" ghe-config --true "mysql.backup.binary" -} - export_command="ghe-export-mysql" if ! is_binary_backup_feature_on; then # binary backup is already compressed From f7e955ee294f74f2f0255d3048229c011c937746 Mon Sep 17 00:00:00 2001 From: Caine Jette Date: Wed, 13 May 2020 18:13:28 -0700 Subject: [PATCH 2/7] Update wording --- bin/ghe-backup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/ghe-backup b/bin/ghe-backup index e86f94ec5..3763aa5bf 100755 --- a/bin/ghe-backup +++ b/bin/ghe-backup @@ -181,9 +181,9 @@ failures="$failures ssh-host-keys" bm_end "ghe-export-ssh-host-keys" if is_binary_backup_feature_on; then - echo "Backing up MySQL database using binary backup ..." + echo "Backing up MySQL database using binary backup strategy ..." else - echo "Backing up MySQL database using logical backup ..." + echo "Backing up MySQL database using logical backup strategy ..." fi ghe-backup-mysql || failures="$failures mysql" From 61c78bdd4e215f2a3e34393860609fe84e91fb00 Mon Sep 17 00:00:00 2001 From: Caine Jette Date: Wed, 13 May 2020 18:17:33 -0700 Subject: [PATCH 3/7] Remove extra declaration of is_binary_backup_feature_on --- share/github-backup-utils/ghe-restore-mysql | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/share/github-backup-utils/ghe-restore-mysql b/share/github-backup-utils/ghe-restore-mysql index 150c93a77..538690635 100755 --- a/share/github-backup-utils/ghe-restore-mysql +++ b/share/github-backup-utils/ghe-restore-mysql @@ -28,14 +28,9 @@ ghe_remote_version_required "$GHE_HOSTNAME" # The directory holding the snapshot to restore snapshot_dir="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT" -# Check if the backup is binary by looking up the sentinel file +# 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" + test -f $snapshot_dir/mysql-binary-backup-sentinel } ssh_config_file_opt= @@ -59,7 +54,7 @@ if is_binary_backup_feature_on; then ghe_mysql_master=$GHE_HOSTNAME fi - # Check if the decompress needed by looking into the sentinel file + # Check if the decompress needed by looking into the sentinel file # In 2.19.5 we compress the binary backup twice if [ "$(cat $snapshot_dir/mysql-binary-backup-sentinel)" = "NO_ADDITIONAL_COMPRESSION" ]; then IMPORT_MYSQL=ghe-import-mysql-xtrabackup @@ -73,9 +68,9 @@ if is_binary_backup_feature_on; then GHE_RESTORE_HOST=$GHE_HOSTNAME fi else - # We do not allow to restore binary backup without "mysql.backup.binary" set + # We do not allow to restore binary backup without "mysql.backup.binary" set if is_binary_backup; then - echo "To restore from a binary backup, you have to set ghe-config \"mysql.backup.binary\" to true" >&2 + echo "To restore from a binary backup, you have to set ghe-config \"mysql.backup.binary\" to true" >&2 exit 2 else # legacy mode From 7be554b8cd963ae0575b74018177605bed4e272d Mon Sep 17 00:00:00 2001 From: Caine Jette Date: Wed, 13 May 2020 18:23:48 -0700 Subject: [PATCH 4/7] Add output to ghe-restore --- share/github-backup-utils/ghe-restore-mysql | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/share/github-backup-utils/ghe-restore-mysql b/share/github-backup-utils/ghe-restore-mysql index 538690635..b7db9a799 100755 --- a/share/github-backup-utils/ghe-restore-mysql +++ b/share/github-backup-utils/ghe-restore-mysql @@ -33,6 +33,18 @@ is_binary_backup(){ test -f $snapshot_dir/mysql-binary-backup-sentinel } +if is_binary_backup_feature_on; then + echo "Appliance is configured for binary backups." +else + echo "Appliance is configured for logical backups." +fi + +if is_binary_backup; then + echo "Backup being restored is a binary backup." +else + echo "Backup being restored is a logical backup." +fi + ssh_config_file_opt= if is_binary_backup_feature_on; then # Feature "mysql.backup.binary" is on, which means new backup scripts are available From b0e690893a238320bf319ab0216db0a398dba0b6 Mon Sep 17 00:00:00 2001 From: Caine Jette Date: Thu, 14 May 2020 04:32:59 +0000 Subject: [PATCH 5/7] Add top level logging to ghe-restore --- bin/ghe-restore | 16 ++++++++++++++-- share/github-backup-utils/ghe-backup-config | 5 +++++ share/github-backup-utils/ghe-restore-mysql | 11 +++-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/bin/ghe-restore b/bin/ghe-restore index e9089da3a..c891793d7 100755 --- a/bin/ghe-restore +++ b/bin/ghe-restore @@ -255,7 +255,19 @@ if [ -s "$GHE_RESTORE_SNAPSHOT_PATH/uuid" ] && ! $CLUSTER; then ghe-ssh "$GHE_HOSTNAME" -- "sudo rm -rf /data/user/consul/raft" fi -echo "Restoring MySQL database ..." +if is_binary_backup_feature_on; then + appliance_strategy="binary" +else + appliance_strategy="logical" +fi + +if is_binary_backup "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT"; then + backup_snapshot_strategy="binary" +else + backup_snapshot_strategy="logical" +fi + +echo "Restoring MySQL database from ${backup_snapshot_strategy} backup snapshot on an appliance configured for ${appliance_strategy} backups ..." ghe-restore-mysql "$GHE_HOSTNAME" 1>&3 commands=(" @@ -318,7 +330,7 @@ if $CLUSTER || [ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.12.9)" ]; the echo \"Restoring Audit logs ...\" ghe-restore-es-audit-log \"$GHE_HOSTNAME\" 1>&3") fi - + commands+=(" echo \"Restoring hookshot logs ...\" ghe-restore-es-hookshot \"$GHE_HOSTNAME\" 1>&3") diff --git a/share/github-backup-utils/ghe-backup-config b/share/github-backup-utils/ghe-backup-config index 493efa51b..176ecdc17 100755 --- a/share/github-backup-utils/ghe-backup-config +++ b/share/github-backup-utils/ghe-backup-config @@ -385,3 +385,8 @@ fix_paths_for_ghe_version() { is_binary_backup_feature_on(){ ghe-ssh "$GHE_HOSTNAME" ghe-config --true "mysql.backup.binary" } + +# Check if the backup is binary by looking up the sentinel file +is_binary_backup(){ + test -f "$1/mysql-binary-backup-sentinel" +} \ No newline at end of file diff --git a/share/github-backup-utils/ghe-restore-mysql b/share/github-backup-utils/ghe-restore-mysql index b7db9a799..f43b5b786 100755 --- a/share/github-backup-utils/ghe-restore-mysql +++ b/share/github-backup-utils/ghe-restore-mysql @@ -28,18 +28,13 @@ ghe_remote_version_required "$GHE_HOSTNAME" # The directory holding the snapshot to restore snapshot_dir="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT" -# Check if the backup is binary by looking up the sentinel file -is_binary_backup(){ - test -f $snapshot_dir/mysql-binary-backup-sentinel -} - if is_binary_backup_feature_on; then echo "Appliance is configured for binary backups." else echo "Appliance is configured for logical backups." fi -if is_binary_backup; then +if is_binary_backup $snapshot_dir; then echo "Backup being restored is a binary backup." else echo "Backup being restored is a logical backup." @@ -48,7 +43,7 @@ fi ssh_config_file_opt= if is_binary_backup_feature_on; then # Feature "mysql.backup.binary" is on, which means new backup scripts are available - if is_binary_backup; then + if is_binary_backup $snapshot_dir; then if $CLUSTER ; then ghe_mysql_master=$(ghe-ssh "$GHE_HOSTNAME" ghe-config "cluster.mysql-master") if [ -z $ghe_mysql_master ]; then @@ -81,7 +76,7 @@ if is_binary_backup_feature_on; then fi else # We do not allow to restore binary backup without "mysql.backup.binary" set - if is_binary_backup; then + if is_binary_backup $snapshot_dir; then echo "To restore from a binary backup, you have to set ghe-config \"mysql.backup.binary\" to true" >&2 exit 2 else From 9f728a165af83fd6df1db288b298fc9c3e8799fa Mon Sep 17 00:00:00 2001 From: Caine Jette Date: Thu, 14 May 2020 05:00:17 +0000 Subject: [PATCH 6/7] Remove logging in ghe-restore-mysql --- share/github-backup-utils/ghe-restore-mysql | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/share/github-backup-utils/ghe-restore-mysql b/share/github-backup-utils/ghe-restore-mysql index f43b5b786..6a546a52a 100755 --- a/share/github-backup-utils/ghe-restore-mysql +++ b/share/github-backup-utils/ghe-restore-mysql @@ -28,18 +28,6 @@ ghe_remote_version_required "$GHE_HOSTNAME" # The directory holding the snapshot to restore snapshot_dir="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT" -if is_binary_backup_feature_on; then - echo "Appliance is configured for binary backups." -else - echo "Appliance is configured for logical backups." -fi - -if is_binary_backup $snapshot_dir; then - echo "Backup being restored is a binary backup." -else - echo "Backup being restored is a logical backup." -fi - ssh_config_file_opt= if is_binary_backup_feature_on; then # Feature "mysql.backup.binary" is on, which means new backup scripts are available From 195882a3c15cca154cc47845c5317a247749995b Mon Sep 17 00:00:00 2001 From: Caine Jette Date: Thu, 14 May 2020 05:01:13 +0000 Subject: [PATCH 7/7] Quote variable for protection --- share/github-backup-utils/ghe-restore-mysql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/github-backup-utils/ghe-restore-mysql b/share/github-backup-utils/ghe-restore-mysql index 6a546a52a..81189f059 100755 --- a/share/github-backup-utils/ghe-restore-mysql +++ b/share/github-backup-utils/ghe-restore-mysql @@ -31,7 +31,7 @@ snapshot_dir="$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT" ssh_config_file_opt= if is_binary_backup_feature_on; then # Feature "mysql.backup.binary" is on, which means new backup scripts are available - if is_binary_backup $snapshot_dir; then + if is_binary_backup "$snapshot_dir"; then if $CLUSTER ; then ghe_mysql_master=$(ghe-ssh "$GHE_HOSTNAME" ghe-config "cluster.mysql-master") if [ -z $ghe_mysql_master ]; then @@ -64,7 +64,7 @@ if is_binary_backup_feature_on; then fi else # We do not allow to restore binary backup without "mysql.backup.binary" set - if is_binary_backup $snapshot_dir; then + if is_binary_backup "$snapshot_dir"; then echo "To restore from a binary backup, you have to set ghe-config \"mysql.backup.binary\" to true" >&2 exit 2 else