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

Commit

Permalink
*: do not return error when backup/restore data is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer committed Mar 23, 2020
1 parent 54e2e9f commit 3e56057
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ func BuildBackupRangeAndSchema(
}

if backupSchemas.Len() == 0 {
return nil, nil, errors.New("nothing to backup")
log.Info("nothing to backup")
return nil, nil, nil
}
return ranges, backupSchemas, nil
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/backup/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *testBackupSchemaSuite) TestBuildBackupRangeAndSchema(c *C) {
c.Assert(err, IsNil)
_, backupSchemas, err := BuildBackupRangeAndSchema(
s.mock.Domain, s.mock.Storage, testFilter, math.MaxUint64)
c.Assert(err, NotNil)
c.Assert(err, IsNil)
c.Assert(backupSchemas, IsNil)

// Database is not exist.
Expand All @@ -53,15 +53,15 @@ func (s *testBackupSchemaSuite) TestBuildBackupRangeAndSchema(c *C) {
c.Assert(err, IsNil)
_, backupSchemas, err = BuildBackupRangeAndSchema(
s.mock.Domain, s.mock.Storage, fooFilter, math.MaxUint64)
c.Assert(err, NotNil)
c.Assert(err, IsNil)
c.Assert(backupSchemas, IsNil)

// Empty databse.
// Empty database.
noFilter, err := filter.New(false, &filter.Rules{})
c.Assert(err, IsNil)
_, backupSchemas, err = BuildBackupRangeAndSchema(
s.mock.Domain, s.mock.Storage, noFilter, math.MaxUint64)
c.Assert(err, NotNil)
c.Assert(err, IsNil)
c.Assert(backupSchemas, IsNil)

tk.MustExec("use test")
Expand Down
5 changes: 3 additions & 2 deletions pkg/restore/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ func FilterDDLJobs(allDDLJobs []*model.Job, tables []*utils.Table) (ddlJobs []*m
tableIDs := make(map[int64]bool)
tableIDs[table.Info.ID] = true
tableNames := make(map[string]bool)
tableNames[table.Info.Name.String()] = true
name := fmt.Sprintf("%s:%s", table.Db.Name.String(), table.Info.Name.String())
tableNames[name] = true
for _, job := range allDDLJobs {
if job.BinlogInfo.TableInfo != nil {
name := job.SchemaName + job.BinlogInfo.TableInfo.Name.String()
name := fmt.Sprintf("%s:%s", job.SchemaName, job.BinlogInfo.TableInfo.Name.String())
if tableIDs[job.TableID] || tableNames[name] {
ddlJobs = append(ddlJobs, job)
tableIDs[job.TableID] = true
Expand Down
4 changes: 4 additions & 0 deletions pkg/task/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
if err != nil {
return err
}
// nothing to backup
if ranges == nil {
return nil
}

ddlJobs := make([]*model.Job, 0)
if cfg.LastBackupTS > 0 {
Expand Down
10 changes: 7 additions & 3 deletions pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
if err != nil {
return err
}
if len(files) == 0 {
return errors.New("all files are filtered out from the backup archive, nothing to restore")
}

var newTS uint64
if client.IsIncremental() {
Expand All @@ -141,6 +138,13 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
if err != nil {
return errors.Trace(err)
}

// 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")
return nil
}

rewriteRules, newTables, err := client.CreateTables(mgr.GetDomain(), tables, newTS)
if err != nil {
return err
Expand Down

0 comments on commit 3e56057

Please sign in to comment.