From e2ff51fb8c76957c4deb72381a3943735d11fce0 Mon Sep 17 00:00:00 2001 From: Zak Zhao <57036248+joccau@users.noreply.github.com> Date: Thu, 9 Feb 2023 23:53:59 +0800 Subject: [PATCH] This is an automated cherry-pick of #41000 Signed-off-by: ti-chi-bot --- br/pkg/backup/client.go | 2 +- br/pkg/utils/schema.go | 6 ++++++ br/tests/br_backup_empty/run.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/br/pkg/backup/client.go b/br/pkg/backup/client.go index ad26ba4b2d5c3..da5f670813145 100644 --- a/br/pkg/backup/client.go +++ b/br/pkg/backup/client.go @@ -283,7 +283,7 @@ func BuildBackupRangeAndSchema( for _, dbInfo := range dbs { // skip system databases - if !tableFilter.MatchSchema(dbInfo.Name.O) || util.IsMemDB(dbInfo.Name.L) { + if !tableFilter.MatchSchema(dbInfo.Name.O) || util.IsMemDB(dbInfo.Name.L) || utils.IsTemplateSysDB(dbInfo.Name) { continue } diff --git a/br/pkg/utils/schema.go b/br/pkg/utils/schema.go index f6374576f43ed..797df838fdffc 100644 --- a/br/pkg/utils/schema.go +++ b/br/pkg/utils/schema.go @@ -16,6 +16,7 @@ import ( // temporaryDBNamePrefix is the prefix name of system db, e.g. mysql system db will be rename to __TiDB_BR_Temporary_mysql const temporaryDBNamePrefix = "__TiDB_BR_Temporary_" +const temporarySysDB = temporaryDBNamePrefix + "mysql" // NeedAutoID checks whether the table needs backing up with an autoid. func NeedAutoID(tblInfo *model.TableInfo) bool { @@ -96,6 +97,11 @@ func EncloseDBAndTable(database, table string) string { return fmt.Sprintf("%s.%s", EncloseName(database), EncloseName(table)) } +// IsTemplateSysDB checks wheterh the dbname is temporary system database(__TiDB_BR_Temporary_mysql). +func IsTemplateSysDB(dbname model.CIStr) bool { + return dbname.O == temporarySysDB +} + // IsSysDB tests whether the database is system DB. // Currently, the only system DB is mysql. func IsSysDB(dbLowerName string) bool { diff --git a/br/tests/br_backup_empty/run.sh b/br/tests/br_backup_empty/run.sh index 943acb9506c81..4db197f8fd572 100644 --- a/br/tests/br_backup_empty/run.sh +++ b/br/tests/br_backup_empty/run.sh @@ -41,14 +41,47 @@ run_sql "CREATE TABLE $DB.usertable1 ( \ PRIMARY KEY (YCSB_KEY) \ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;" +<<<<<<< HEAD echo "backup start..." run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/empty_table" run_sql "DROP DATABASE $DB;" echo "restore start..." +======= +# backup empty table +echo "backup empty table start..." +run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/empty_table" + +while [ $i -le $DB_COUNT ]; do + run_sql "DROP DATABASE $DB$i;" + i=$(($i+1)) +done + +# restore empty table. +echo "restore empty table start..." +>>>>>>> 7f88e73af6 (br: skip template system table __TiDB_BR_Temporary_mysql when backup (#41000)) run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/empty_table" # insert one row to make sure table is restored. run_sql "INSERT INTO $DB.usertable1 VALUES (\"a\", \"b\");" +<<<<<<< HEAD run_sql "DROP DATABASE $DB" +======= +while [ $i -le $DB_COUNT ]; do + run_sql "DROP DATABASE $DB$i;" + i=$(($i+1)) +done + + +# backup, skip temporary system database(__TiDB_BR_Temporary_mysql) when backup +run_sql "CREATE DATABASE __TiDB_BR_Temporary_mysql"; +run_sql "CREATE TABLE __TiDB_BR_Temporary_mysql.tables_priv(id int);"; +echo "backup and skip __TiDB_BR_Temporary_mysql start..." +run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/skip_temporary_mysql" + +# restore successfully without panic. +run_sql "DROP DATABASE __TiDB_BR_Temporary_mysql"; +echo "restore the data start..." +run_br restore full -s "local://$TEST_DIR/skip_temporary_mysql" --pd $PD_ADDR --ratelimit 1024 +>>>>>>> 7f88e73af6 (br: skip template system table __TiDB_BR_Temporary_mysql when backup (#41000))