Skip to content

Commit aa03b96

Browse files
committed
Add logic for migration from fallback dir
1 parent acf263c commit aa03b96

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

pbm/restore/physical.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,7 @@ func (r *PhysRestore) close(noerr, cleanup bool) {
234234
r.log.Warning("remove file <%s>: %v", backup.FilelistName, err)
235235
}
236236
} else if cleanup { // clean-up dbpath on err if needed
237-
r.log.Debug("clean-up dbpath")
238-
err := removeAll(r.dbpath, r.log)
239-
if err != nil {
240-
r.log.Error("flush dbpath %s: %v", r.dbpath, err)
241-
}
237+
r.migrateFromFallbackDirToDbDir()
242238
}
243239
if r.stopHB != nil {
244240
close(r.stopHB)
@@ -293,10 +289,10 @@ func (r *PhysRestore) flush(ctx context.Context) error {
293289
}
294290
}
295291

296-
r.log.Debug("remove old data")
297-
err = removeAll(r.dbpath, r.log)
292+
r.log.Debug("move data to fallback path")
293+
err = r.migrateDbDirToFallbackDir()
298294
if err != nil {
299-
return errors.Wrapf(err, "flush dbpath %s", r.dbpath)
295+
return errors.Wrapf(err, "move files to fallback path")
300296
}
301297

302298
return nil
@@ -309,13 +305,12 @@ func (r *PhysRestore) migrateDbDirToFallbackDir() error {
309305
fallbackPath := filepath.Join(dbpath, fallbackDir)
310306
r.log.Debug("dbpath: %s, fallbackPath: %s", dbpath, fallbackPath)
311307

312-
r.log.Debug("remove old %s", fallbackPath)
313308
err := os.RemoveAll(fallbackPath)
314309
if err != nil {
315310
return errors.Wrap(err, "remove fallback db path")
316311
}
317312

318-
r.log.Debug("create new %s", fallbackPath)
313+
r.log.Debug("create %s", fallbackPath)
319314
info, err := os.Stat(dbpath)
320315
if err != nil {
321316
return errors.Wrap(err, "stat")
@@ -333,6 +328,23 @@ func (r *PhysRestore) migrateDbDirToFallbackDir() error {
333328
return nil
334329
}
335330

331+
// migrateFromFallbackDirToDbDir wipe up dbpath dir and
332+
// moves all content from fallback path.
333+
func (r *PhysRestore) migrateFromFallbackDirToDbDir() error {
334+
r.log.Debug("clean-up dbpath")
335+
err := removeAll(r.dbpath, r.log)
336+
if err != nil {
337+
r.log.Error("flush dbpath %s: %v", r.dbpath, err)
338+
}
339+
340+
err = r.moveFromFallback()
341+
if err != nil {
342+
r.log.Error("moving from %s: %v", fallbackDir, err)
343+
}
344+
345+
return nil
346+
}
347+
336348
// moveFromFallback moves all files/dirs from fallback dir to dbpath dir.
337349
func (r *PhysRestore) moveFromFallback() error {
338350
return moveAll(

0 commit comments

Comments
 (0)