@@ -374,6 +374,10 @@ func (r *PhysRestore) migrateDBDirToFallbackDir() error {
374
374
if err != nil {
375
375
return errors .Wrap (err , "remove fallback db path" )
376
376
}
377
+ err = removeInternalMongoLogs (dbpath , r .log )
378
+ if err != nil {
379
+ return errors .Wrap (err , "remove internal mongod log(s)" )
380
+ }
377
381
378
382
r .log .Debug ("create %s" , fallbackPath )
379
383
info , err := os .Stat (dbpath )
@@ -2588,6 +2592,8 @@ func moveAll(fromDir, toDir string, toIgnore []string, l log.LogEvent) error {
2588
2592
return nil
2589
2593
}
2590
2594
2595
+ // removeAll removes all files and directories from specified dir.
2596
+ // It ignores files selected with filesSkipRules parameter.
2591
2597
func removeAll (dir string , l log.LogEvent , fileSkipRules ... fileSkipRule ) error {
2592
2598
d , err := os .Open (dir )
2593
2599
if err != nil {
@@ -2612,6 +2618,33 @@ func removeAll(dir string, l log.LogEvent, fileSkipRules ...fileSkipRule) error
2612
2618
return nil
2613
2619
}
2614
2620
2621
+ // removeInternalMongoLogs removes internal mongod logs from directory.
2622
+ // It'll remove everything that starts with 'pbm.restore.log'
2623
+ func removeInternalMongoLogs (dir string , l log.LogEvent ) error {
2624
+ d , err := os .Open (dir )
2625
+ if err != nil {
2626
+ return errors .Wrap (err , "open dir" )
2627
+ }
2628
+ defer d .Close ()
2629
+
2630
+ names , err := d .Readdirnames (- 1 )
2631
+ if err != nil {
2632
+ return errors .Wrap (err , "read file names" )
2633
+ }
2634
+ for _ , n := range names {
2635
+ if isInternalMongoLog (n ) {
2636
+ err = os .RemoveAll (filepath .Join (dir , n ))
2637
+ if err != nil {
2638
+ return errors .Wrapf (err , "remove '%s" , n )
2639
+ }
2640
+
2641
+ l .Debug ("remove %s" , filepath .Join (dir , n ))
2642
+ }
2643
+ }
2644
+
2645
+ return nil
2646
+ }
2647
+
2615
2648
// isInternalMongoLog checks whether the file with the name f
2616
2649
// is internal mongo log file
2617
2650
func isInternalMongoLog (f string ) bool {
0 commit comments