@@ -234,26 +234,33 @@ func (r *PhysRestore) close(noerr, cleanup bool) {
234
234
if err != nil && ! errors .Is (err , os .ErrNotExist ) {
235
235
r .log .Warning ("remove file <%s>: %v" , backup .FilelistName , err )
236
236
}
237
- } else if cleanup { // clean-up dbpath on err if needed
238
- r .log .Debug ("wait for cluster status" )
239
- cStatus , err := r .waitClusterStatus ()
237
+ }
238
+
239
+ r .log .Debug ("wait for cluster status" )
240
+ cStatus , err := r .waitClusterStatus ()
241
+ if err != nil {
242
+ r .log .Warning ("waiting for cluster status during cleanup: %v" , err )
243
+ }
244
+ if cStatus == defs .StatusError {
245
+ r .log .Warning ("apply db data from %s" , fallbackDir )
246
+ err := r .migrateFromFallbackDirToDBDir ()
240
247
if err != nil {
241
- r .log .Warning ( "waiting for cluster status during cleanup : %v" , err )
248
+ r .log .Error ( "migrate from fallback dir : %v" , err )
242
249
}
243
-
244
- if cStatus == defs .StatusError {
245
- err := r .migrateFromFallbackDirToDBDir ()
246
- if err != nil {
247
- r .log .Error ("migrate from fallback dir: %v" , err )
248
- }
249
- } else { // cluster status is done or partlyDone
250
- r .log .Debug ("clean-up dbpath" )
251
- err := removeAll (r .dbpath , nil , r .log )
252
- if err != nil {
253
- r .log .Error ("flush dbpath %s: %v" , r .dbpath , err )
254
- }
250
+ } else if cleanup { // clean-up dbpath on err if needed (cluster is done or partlyDone)
251
+ r .log .Debug ("clean-up dbpath" )
252
+ err := removeAll (r .dbpath , nil , r .log )
253
+ if err != nil {
254
+ r .log .Error ("flush dbpath %s: %v" , r .dbpath , err )
255
+ }
256
+ } else { // free space by just deleting fallback dir in any other case
257
+ r .log .Debug ("remove fallback dir" )
258
+ err := r .removeFallback ()
259
+ if err != nil {
260
+ r .log .Error ("flush fallback: %v" , err )
255
261
}
256
262
}
263
+
257
264
if r .stopHB != nil {
258
265
close (r .stopHB )
259
266
}
@@ -428,6 +435,14 @@ func (r *PhysRestore) moveToFallback() error {
428
435
)
429
436
}
430
437
438
+ // removeFallback removes fallback dir
439
+ func (r * PhysRestore ) removeFallback () error {
440
+ dbpath := filepath .Clean (r .dbpath )
441
+ fallbackPath := filepath .Join (dbpath , fallbackDir )
442
+ err := os .RemoveAll (fallbackPath )
443
+ return errors .Wrap (err , "remove fallback db path" )
444
+ }
445
+
431
446
func nodeShutdown (ctx context.Context , m * mongo.Client ) error {
432
447
err := m .Database ("admin" ).RunCommand (ctx , bson.D {{"shutdown" , 1 }}).Err ()
433
448
if err == nil || strings .Contains (err .Error (), "socket was unexpectedly closed" ) {
0 commit comments