Skip to content

Commit 7f88e73

Browse files
authored
br: skip template system table __TiDB_BR_Temporary_mysql when backup (#41000)
close #40797
1 parent 6e0c38a commit 7f88e73

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

br/pkg/backup/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func BuildBackupRangeAndSchema(
529529

530530
for _, dbInfo := range dbs {
531531
// skip system databases
532-
if !tableFilter.MatchSchema(dbInfo.Name.O) || util.IsMemDB(dbInfo.Name.L) {
532+
if !tableFilter.MatchSchema(dbInfo.Name.O) || util.IsMemDB(dbInfo.Name.L) || utils.IsTemplateSysDB(dbInfo.Name) {
533533
continue
534534
}
535535

br/pkg/utils/schema.go

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
// temporaryDBNamePrefix is the prefix name of system db, e.g. mysql system db will be rename to __TiDB_BR_Temporary_mysql
1818
const temporaryDBNamePrefix = "__TiDB_BR_Temporary_"
19+
const temporarySysDB = temporaryDBNamePrefix + "mysql"
1920

2021
// NeedAutoID checks whether the table needs backing up with an autoid.
2122
func NeedAutoID(tblInfo *model.TableInfo) bool {
@@ -96,6 +97,11 @@ func EncloseDBAndTable(database, table string) string {
9697
return fmt.Sprintf("%s.%s", EncloseName(database), EncloseName(table))
9798
}
9899

100+
// IsTemplateSysDB checks wheterh the dbname is temporary system database(__TiDB_BR_Temporary_mysql).
101+
func IsTemplateSysDB(dbname model.CIStr) bool {
102+
return dbname.O == temporarySysDB
103+
}
104+
99105
// IsSysDB tests whether the database is system DB.
100106
// Currently, the only system DB is mysql.
101107
func IsSysDB(dbLowerName string) bool {

br/tests/br_backup_empty/run.sh

+14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ run_sql "CREATE TABLE ${DB}1.usertable1 ( \
6767
PRIMARY KEY (YCSB_KEY) \
6868
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"
6969

70+
# backup empty table
7071
echo "backup empty table start..."
7172
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/empty_table"
7273

@@ -75,6 +76,7 @@ while [ $i -le $DB_COUNT ]; do
7576
i=$(($i+1))
7677
done
7778

79+
# restore empty table.
7880
echo "restore empty table start..."
7981
run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/empty_table"
8082

@@ -85,3 +87,15 @@ while [ $i -le $DB_COUNT ]; do
8587
run_sql "DROP DATABASE $DB$i;"
8688
i=$(($i+1))
8789
done
90+
91+
92+
# backup, skip temporary system database(__TiDB_BR_Temporary_mysql) when backup
93+
run_sql "CREATE DATABASE __TiDB_BR_Temporary_mysql";
94+
run_sql "CREATE TABLE __TiDB_BR_Temporary_mysql.tables_priv(id int);";
95+
echo "backup and skip __TiDB_BR_Temporary_mysql start..."
96+
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/skip_temporary_mysql"
97+
98+
# restore successfully without panic.
99+
run_sql "DROP DATABASE __TiDB_BR_Temporary_mysql";
100+
echo "restore the data start..."
101+
run_br restore full -s "local://$TEST_DIR/skip_temporary_mysql" --pd $PD_ADDR --ratelimit 1024

0 commit comments

Comments
 (0)