Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

restore: support restore empty databases and tables (#317) #318

Merged
merged 3 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
}

// nothing to restore, maybe only ddl changes in incremental restore
if len(files) == 0 {
log.Info("all files are filtered out from the backup archive, nothing to restore")
if len(dbs) == 0 && len(tables) == 0 {
log.Info("nothing to restore, all databases and tables are filtered out")
// even nothing to restore, we show a success message since there is no failure.
summary.SetSuccessStatus(true)
return nil
Expand All @@ -187,6 +187,12 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
if err != nil {
return err
}
if len(files) == 0 {
log.Info("no files, empty databases and tables are restored")
summary.SetSuccessStatus(true)
return nil
}

placementRules, err := client.GetPlacementRules(cfg.PD)
if err != nil {
return err
Expand Down Expand Up @@ -335,6 +341,9 @@ func filterRestoreFiles(
tables = append(tables, table)
}
}
if len(dbs) == 0 && len(tables) != 0 {
err = errors.New("invalid backup, contain tables but no databases")
}
return
}

Expand Down
23 changes: 21 additions & 2 deletions tests/br_backup_empty/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,40 @@
# limitations under the License.

set -eu
DB="$TEST_NAME"

# backup empty.
echo "backup start..."
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/empty" --ratelimit 5 --concurrency 4
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/empty_db" --ratelimit 5 --concurrency 4
if [ $? -ne 0 ]; then
echo "TEST: [$TEST_NAME] failed on backup empty cluster!"
exit 1
fi

# restore empty.
echo "restore start..."
run_br restore full -s "local://$TEST_DIR/empty" --pd $PD_ADDR --ratelimit 1024
run_br restore full -s "local://$TEST_DIR/empty_db" --pd $PD_ADDR --ratelimit 1024
if [ $? -ne 0 ]; then
echo "TEST: [$TEST_NAME] failed on restore empty cluster!"
exit 1
fi

# backup and restore empty tables.
run_sql "CREATE DATABASE $DB;"
run_sql "CREATE TABLE $DB.usertable1 ( \
YCSB_KEY varchar(64) NOT NULL, \
FIELD0 varchar(1) DEFAULT NULL, \
PRIMARY KEY (YCSB_KEY) \
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;"

echo "backup start..."
run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/empty_table" --ratelimit 5 --concurrency 4

run_sql "DROP DATABASE $DB;"
echo "restore start..."
run_br --pd $PD_ADDR restore full -s "local://$TEST_DIR/empty_table" --ratelimit 5 --concurrency 4

# insert one row to make sure table is restored.
run_sql "INSERT INTO $DB.usertable1 VALUES (\"a\", \"b\");"

echo "TEST: [$TEST_NAME] successed!"