@@ -404,17 +404,33 @@ func (d *DumpJob) getPassword() string {
404
404
}
405
405
406
406
func (d * DumpJob ) cleanupDumpLocation (ctx context.Context , dumpContID string ) error {
407
- if d .DumpOptions .DumpLocation != "" && d .DumpOptions .Restore .Enabled {
408
- cleanupCmd := []string {"rm" , "-rf" , path .Join (d .DumpOptions .DumpLocation , "*" )}
407
+ if d .DumpOptions .DumpLocation == "" || d .DumpOptions .Restore .Enabled {
408
+ return nil
409
+ }
409
410
410
- log .Msg ("Running cleanup command: " , cleanupCmd )
411
+ ls , err := tools .LsContainerDirectory (ctx , d .dockerClient , dumpContID , d .DumpOptions .DumpLocation )
412
+ if err != nil {
413
+ return errors .Wrap (err , "failed to clean up dump location" )
414
+ }
411
415
412
- if out , err := tools .ExecCommandWithOutput (ctx , d .dockerClient , dumpContID , types.ExecConfig {
413
- Cmd : cleanupCmd ,
414
- }); err != nil {
415
- log .Dbg (out )
416
- return errors .Wrap (err , "failed to clean up dump location" )
417
- }
416
+ if len (ls ) == 0 {
417
+ return nil
418
+ }
419
+
420
+ cleanupCmd := []string {"rm" , "-rf" }
421
+
422
+ for _ , dbName := range ls {
423
+ cleanupCmd = append (cleanupCmd , path .Join (d .DumpOptions .DumpLocation , dbName ))
424
+ }
425
+
426
+ log .Msg ("Running cleanup command: " , cleanupCmd )
427
+
428
+ if out , err := tools .ExecCommandWithOutput (ctx , d .dockerClient , dumpContID , types.ExecConfig {
429
+ Tty : true ,
430
+ Cmd : cleanupCmd ,
431
+ }); err != nil {
432
+ log .Dbg (out )
433
+ return errors .Wrap (err , "failed to clean up dump location" )
418
434
}
419
435
420
436
return nil
@@ -443,12 +459,13 @@ func (d *DumpJob) dumpDatabase(ctx context.Context, dumpContID, dbName string, d
443
459
}
444
460
445
461
func setupPGData (ctx context.Context , dockerClient * client.Client , dataDir string , dumpContID string ) error {
446
- isEmpty , err := tools .IsEmptyContainerDirectory (ctx , dockerClient , dumpContID , dataDir )
462
+ entryList , err := tools .LsContainerDirectory (ctx , dockerClient , dumpContID , dataDir )
447
463
if err != nil {
448
464
return errors .Wrap (err , "failed to explore the data directory" )
449
465
}
450
466
451
- if ! isEmpty {
467
+ // Already initialized.
468
+ if len (entryList ) != 0 {
452
469
return nil
453
470
}
454
471
0 commit comments