@@ -234,11 +234,7 @@ func (r *PhysRestore) close(noerr, cleanup bool) {
234
234
r .log .Warning ("remove file <%s>: %v" , backup .FilelistName , err )
235
235
}
236
236
} 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 ()
242
238
}
243
239
if r .stopHB != nil {
244
240
close (r .stopHB )
@@ -293,10 +289,10 @@ func (r *PhysRestore) flush(ctx context.Context) error {
293
289
}
294
290
}
295
291
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 ( )
298
294
if err != nil {
299
- return errors .Wrapf (err , "flush dbpath %s" , r . dbpath )
295
+ return errors .Wrapf (err , "move files to fallback path" )
300
296
}
301
297
302
298
return nil
@@ -309,13 +305,12 @@ func (r *PhysRestore) migrateDbDirToFallbackDir() error {
309
305
fallbackPath := filepath .Join (dbpath , fallbackDir )
310
306
r .log .Debug ("dbpath: %s, fallbackPath: %s" , dbpath , fallbackPath )
311
307
312
- r .log .Debug ("remove old %s" , fallbackPath )
313
308
err := os .RemoveAll (fallbackPath )
314
309
if err != nil {
315
310
return errors .Wrap (err , "remove fallback db path" )
316
311
}
317
312
318
- r .log .Debug ("create new %s" , fallbackPath )
313
+ r .log .Debug ("create %s" , fallbackPath )
319
314
info , err := os .Stat (dbpath )
320
315
if err != nil {
321
316
return errors .Wrap (err , "stat" )
@@ -333,6 +328,23 @@ func (r *PhysRestore) migrateDbDirToFallbackDir() error {
333
328
return nil
334
329
}
335
330
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
+
336
348
// moveFromFallback moves all files/dirs from fallback dir to dbpath dir.
337
349
func (r * PhysRestore ) moveFromFallback () error {
338
350
return moveAll (
0 commit comments