@@ -468,20 +468,38 @@ func InitializeWorkspace(ctx context.Context, location string, remoteStorage sto
468468 }
469469 }
470470
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 ()
472477 hasBackup , err := remoteStorage .Download (ctx , location , storage .DefaultBackup , cfg .mappings )
473478 if err != nil {
474479 return src , nil , xerrors .Errorf ("cannot restore backup: %w" , err )
475480 }
481+ downloadDuration := time .Since (downloadStart )
476482
477483 span .SetTag ("hasBackup" , hasBackup )
478484 if hasBackup {
479485 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" )
484490 }
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 )
485503 }
486504
487505 return
0 commit comments