From 3e560576937057d86622b2a68860985e96bbb474 Mon Sep 17 00:00:00 2001 From: luancheng Date: Mon, 23 Mar 2020 21:21:24 +0800 Subject: [PATCH] *: do not return error when backup/restore data is empty --- pkg/backup/client.go | 3 ++- pkg/backup/schema_test.go | 8 ++++---- pkg/restore/db.go | 5 +++-- pkg/task/backup.go | 4 ++++ pkg/task/restore.go | 10 +++++++--- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pkg/backup/client.go b/pkg/backup/client.go index 9693b6b5f..a5efe9408 100644 --- a/pkg/backup/client.go +++ b/pkg/backup/client.go @@ -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 } diff --git a/pkg/backup/schema_test.go b/pkg/backup/schema_test.go index 3b3bef897..f0dec8072 100644 --- a/pkg/backup/schema_test.go +++ b/pkg/backup/schema_test.go @@ -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. @@ -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") diff --git a/pkg/restore/db.go b/pkg/restore/db.go index f23200033..90ad64053 100644 --- a/pkg/restore/db.go +++ b/pkg/restore/db.go @@ -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 diff --git a/pkg/task/backup.go b/pkg/task/backup.go index 5944a22a0..6c38733b8 100644 --- a/pkg/task/backup.go +++ b/pkg/task/backup.go @@ -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 { diff --git a/pkg/task/restore.go b/pkg/task/restore.go index 7d5dd6846..eee6434b9 100644 --- a/pkg/task/restore.go +++ b/pkg/task/restore.go @@ -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() { @@ -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