@@ -93,6 +93,7 @@ type PhysRestore struct {
93
93
bcpStg storage.Storage
94
94
bcp * backup.BackupMeta
95
95
files []files
96
+ bcpSizeRS int64 // total uncompressed size of the backup for RS (including all increments)
96
97
restoreTS primitive.Timestamp
97
98
98
99
confOpts * config.RestoreConf
@@ -2341,6 +2342,9 @@ const bcpDir = "__dir__"
2341
2342
//
2342
2343
// The restore should be done in reverse order. Applying files (diffs)
2343
2344
// starting from the base and moving forward in time up to the target backup.
2345
+ //
2346
+ // Additionally total uncompressed backup size for RS is callculated
2347
+ // in this method.
2344
2348
func (r * PhysRestore ) setBcpFiles (ctx context.Context ) error {
2345
2349
bcp := r .bcp
2346
2350
@@ -2372,6 +2376,8 @@ func (r *PhysRestore) setBcpFiles(ctx context.Context) error {
2372
2376
targetFiles [f .Name ] = false
2373
2377
}
2374
2378
2379
+ r .bcpSizeRS = rs .SizeUncompressed
2380
+
2375
2381
for {
2376
2382
data := files {
2377
2383
BcpName : bcp .Name ,
@@ -2397,6 +2403,10 @@ func (r *PhysRestore) setBcpFiles(ctx context.Context) error {
2397
2403
r .files = append (r .files , data )
2398
2404
2399
2405
if bcp .SrcBackup == "" {
2406
+ // if base backup doesn't have size, we cannot calculate total size
2407
+ if rs .SizeUncompressed == 0 {
2408
+ r .bcpSizeRS = 0 // zero is used as the flag
2409
+ }
2400
2410
break
2401
2411
}
2402
2412
@@ -2407,6 +2417,7 @@ func (r *PhysRestore) setBcpFiles(ctx context.Context) error {
2407
2417
return errors .Wrapf (err , "get source backup" )
2408
2418
}
2409
2419
rs = getRS (bcp , setName )
2420
+ r .bcpSizeRS += rs .SizeUncompressed
2410
2421
2411
2422
if version .HasFilelistFile (bcp .PBMVersion ) {
2412
2423
filelistPath := path .Join (bcp .Name , setName , backup .FilelistName )
@@ -2548,6 +2559,15 @@ func (r *PhysRestore) prepareBackup(ctx context.Context, backupName string) erro
2548
2559
return errors .Wrap (err , "get data for restore" )
2549
2560
}
2550
2561
2562
+ r .log .Debug ("restore opts: fallbackEnabled: %t; allowPartlyDone: %t" ,
2563
+ r .fallback , r .allowPartlyDone )
2564
+ if r .fallback {
2565
+ err = r .checkDiskSpace (r .bcpSizeRS )
2566
+ if err != nil {
2567
+ return errors .Wrap (err , "check disk space" )
2568
+ }
2569
+ }
2570
+
2551
2571
s , err := topo .ClusterMembers (ctx , r .leadConn .MongoClient ())
2552
2572
if err != nil {
2553
2573
return errors .Wrap (err , "get cluster members" )
@@ -2572,15 +2592,6 @@ func (r *PhysRestore) prepareBackup(ctx context.Context, backupName string) erro
2572
2592
2573
2593
setName := mapRevRS (r .nodeInfo .SetName )
2574
2594
2575
- r .log .Debug ("restore opts: --fallback-enabled: %t; --allow-partly-done: %t" ,
2576
- r .fallback , r .allowPartlyDone )
2577
- if r .fallback && r .bcp .RS (setName ) != nil {
2578
- err = r .checkDiskSpace (r .bcp .RS (setName ).Size )
2579
- if err != nil {
2580
- return errors .Wrap (err , "check disk space" )
2581
- }
2582
- }
2583
-
2584
2595
var ok bool
2585
2596
for _ , v := range r .bcp .Replsets {
2586
2597
if v .Name == setName {
@@ -2663,7 +2674,7 @@ func (r *PhysRestore) checkDiskSpace(bcpSize int64) error {
2663
2674
// disableFallbackForOldBackup set fallback option to false due to backup incompatibility
2664
2675
func (r * PhysRestore ) disableFallbackForOldBackup () {
2665
2676
r .fallback = false
2666
- r .log .Debug ("restore opts: --fallback-enabled : %t; --allow-partly-done : %t" ,
2677
+ r .log .Debug ("restore opts: fallbackEnabled : %t; allowPartlyDone : %t" ,
2667
2678
r .fallback , r .allowPartlyDone )
2668
2679
}
2669
2680
0 commit comments