@@ -468,20 +468,38 @@ func InitializeWorkspace(ctx context.Context, location string, remoteStorage sto
468
468
}
469
469
}
470
470
471
- // Run the initializer
471
+ // Try to download a backup first
472
+ initialSize , fsErr := getFsUsage ()
473
+ if fsErr != nil {
474
+ log .WithError (fsErr ).Error ("could not get disk usage" )
475
+ }
476
+ downloadStart := time .Now ()
472
477
hasBackup , err := remoteStorage .Download (ctx , location , storage .DefaultBackup , cfg .mappings )
473
478
if err != nil {
474
479
return src , nil , xerrors .Errorf ("cannot restore backup: %w" , err )
475
480
}
481
+ downloadDuration := time .Since (downloadStart )
476
482
477
483
span .SetTag ("hasBackup" , hasBackup )
478
484
if hasBackup {
479
485
src = csapi .WorkspaceInitFromBackup
480
- } else {
481
- src , stats , err = cfg . Initializer . Run ( ctx , cfg . mappings )
482
- if err != nil {
483
- return src , nil , xerrors . Errorf ( "cannot initialize workspace: %w" , err )
486
+
487
+ currentSize , fsErr := getFsUsage ( )
488
+ if fsErr != nil {
489
+ log . WithError ( fsErr ). Error ( "could not get disk usage" )
484
490
}
491
+ stats = []csapi.InitializerMetric {{
492
+ Type : "fromBackup" ,
493
+ Duration : downloadDuration ,
494
+ Size : currentSize - initialSize ,
495
+ }}
496
+ return
497
+ }
498
+
499
+ // If there is not backup, run the initializer
500
+ src , stats , err = cfg .Initializer .Run (ctx , cfg .mappings )
501
+ if err != nil {
502
+ return src , nil , xerrors .Errorf ("cannot initialize workspace: %w" , err )
485
503
}
486
504
487
505
return
0 commit comments