From 03f38173b2283dfd473031ae4ee254251bd1ba57 Mon Sep 17 00:00:00 2001 From: juruen Date: Fri, 6 Dec 2019 02:22:58 -0800 Subject: [PATCH] make sure the absence of audit_entries table is not fatal --- share/github-backup-utils/ghe-backup-audit-log | 10 +++++++++- share/github-backup-utils/ghe-restore-audit-log | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/share/github-backup-utils/ghe-backup-audit-log b/share/github-backup-utils/ghe-backup-audit-log index 9366246f..6030b2c5 100755 --- a/share/github-backup-utils/ghe-backup-audit-log +++ b/share/github-backup-utils/ghe-backup-audit-log @@ -29,6 +29,11 @@ is_skip_truncate_enabled(){ ghe-ssh "$host" test -e "$GHE_REMOTE_DATA_USER_DIR/common/audit-log-import/skip_truncate" } +# Check whether the audit_entries table is deleted +audit_entries_deleted(){ + [ -z "$(ghe-ssh "$host" -- "/usr/local/share/enterprise/github-mysql 'SHOW TABLES LIKE \"audit_entries\"'")" ] +} + is_binary_backup(){ ghe-ssh "$host" ghe-config --true "mysql.backup.binary" } @@ -38,7 +43,10 @@ backup_mysql(){ ghe_verbose "Skip backup audit_entries for Mysql since it is using binary backup" return fi - if is_skip_truncate_enabled; then + + if audit_entries_deleted; then + ghe_verbose "audit_entries table does not exist" + elif is_skip_truncate_enabled; then # As skip_truncate exists, we need to also backup the audit entries # in MySQL because Elasticsearch may not be fully synced. "${base_path}/ghe-backup-mysql-audit-log" diff --git a/share/github-backup-utils/ghe-restore-audit-log b/share/github-backup-utils/ghe-restore-audit-log index 75fe0d41..8da16b36 100755 --- a/share/github-backup-utils/ghe-restore-audit-log +++ b/share/github-backup-utils/ghe-restore-audit-log @@ -91,6 +91,11 @@ restore_mysql(){ ghe_verbose "Restoring MySQL audit logs ..." + if ! mysql_table_schema_available; then + ghe_verbose "schema.gz does not exist" + return + fi + "${base_path}/ghe-restore-mysql-audit-log" "$GHE_HOSTNAME" "$only_schema" }