Skip to content

Commit

Permalink
Merge pull request #172 from wayblink/fix-com
Browse files Browse the repository at this point in the history
Fix compatibility to old backup without database info
  • Loading branch information
lentitude2tk authored Jul 26, 2023
2 parents 7937451 + e37711e commit f276c61
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 16 additions & 0 deletions core/backup_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 9 additions & 4 deletions core/backup_impl_restore_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,19 @@ 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)
}
}
} 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)
}
Expand All @@ -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)
Expand Down

0 comments on commit f276c61

Please sign in to comment.