diff --git a/core/backup_context_test.go b/core/backup_context_test.go index b8a91e7f..41068d01 100644 --- a/core/backup_context_test.go +++ b/core/backup_context_test.go @@ -224,6 +224,22 @@ func TestGetBackupUnexistBackupName(t *testing.T) { } func TestRestoreBackup(t *testing.T) { + var params paramtable.BackupParams + params.Init() + context := context.Background() + backup := CreateBackupContext(context, params) + backup.Start() + backupName := "demo" + //fmt.Sprintf("test_%d", rand.Int()) + + restoreResp := backup.RestoreBackup(context, &backuppb.RestoreBackupRequest{ + BackupName: backupName, + DbCollections: utils.WrapDBCollections("{\"default\":[]}"), + }) + log.Info("restore backup", zap.Any("resp", restoreResp)) +} + +func TestCreateAndRestoreBackup(t *testing.T) { var params paramtable.BackupParams params.Init() context := context.Background() diff --git a/core/backup_impl_restore_backup.go b/core/backup_impl_restore_backup.go index b46c1a5e..a95dd249 100644 --- a/core/backup_impl_restore_backup.go +++ b/core/backup_impl_restore_backup.go @@ -117,6 +117,9 @@ func (b *BackupContext) RestoreBackup(ctx context.Context, request *backuppb.Res for db, collections := range dbCollections { if len(collections) == 0 { for _, collectionBackup := range backup.GetCollectionBackups() { + if collectionBackup.GetDbName() == "" { + collectionBackup.DbName = "default" + } if collectionBackup.GetDbName() == db { toRestoreCollectionBackups = append(toRestoreCollectionBackups, collectionBackup) } @@ -124,6 +127,9 @@ func (b *BackupContext) RestoreBackup(ctx context.Context, request *backuppb.Res } else { for _, coll := range collections { for _, collectionBackup := range backup.GetCollectionBackups() { + if collectionBackup.GetDbName() == "" { + collectionBackup.DbName = "default" + } if collectionBackup.GetDbName() == db && collectionBackup.CollectionName == coll { toRestoreCollectionBackups = append(toRestoreCollectionBackups, collectionBackup) } @@ -145,11 +151,10 @@ func (b *BackupContext) RestoreBackup(ctx context.Context, request *backuppb.Res collectionNameDict[fullCollectionName] = true } for _, collectionBackup := range backup.GetCollectionBackups() { - dbName := "default" - if collectionBackup.GetDbName() != "" { - dbName = collectionBackup.GetDbName() + if collectionBackup.GetDbName() == "" { + collectionBackup.DbName = "default" } - fullCollectionName := dbName + "." + collectionBackup.GetCollectionName() + fullCollectionName := collectionBackup.GetDbName() + "." + collectionBackup.GetCollectionName() collectionBackup.GetCollectionName() if collectionNameDict[fullCollectionName] { toRestoreCollectionBackups = append(toRestoreCollectionBackups, collectionBackup)