Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#41000
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
joccau authored and ti-chi-bot committed Feb 9, 2023
1 parent 52ae590 commit e2ff51f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion br/pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions br/pkg/utils/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
33 changes: 33 additions & 0 deletions br/tests/br_backup_empty/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit e2ff51f

Please sign in to comment.