diff --git a/br/pkg/backup/client.go b/br/pkg/backup/client.go index 49bba26612578..36295c3293a00 100644 --- a/br/pkg/backup/client.go +++ b/br/pkg/backup/client.go @@ -528,7 +528,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 8ceba24e140ad..0987e446bfc49 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 41ca818139ba4..0289f1d401068 100644 --- a/br/tests/br_backup_empty/run.sh +++ b/br/tests/br_backup_empty/run.sh @@ -67,6 +67,7 @@ run_sql "CREATE TABLE ${DB}1.usertable1 ( \ PRIMARY KEY (YCSB_KEY) \ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;" +# backup empty table echo "backup empty table start..." run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/empty_table" @@ -75,6 +76,7 @@ while [ $i -le $DB_COUNT ]; do i=$(($i+1)) done +# restore empty table. echo "restore empty table start..." run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/empty_table" @@ -85,3 +87,15 @@ 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