diff --git a/deltablock.go b/deltablock.go index 626925e93..f3172ef50 100644 --- a/deltablock.go +++ b/deltablock.go @@ -934,8 +934,14 @@ func RestoreDeltaBlockBackupIncrementally(ctx context.Context, config *DeltaRest return err } go func() { + var err error + finalProgress := 0 + defer func() { _ = deltaOps.CloseVolumeDev(volDev) + + deltaOps.UpdateRestoreStatus(volDevName, finalProgress, err) + if unlockErr := lock.Unlock(); unlockErr != nil { logrus.WithError(unlockErr).Warn("Failed to unlock") } @@ -948,18 +954,18 @@ func RestoreDeltaBlockBackupIncrementally(ctx context.Context, config *DeltaRest // We want to truncate regular files, but not device if stat.Mode().IsRegular() { log.Infof("Truncate %v to size %v", volDevName, vol.Size) - if err := volDev.Truncate(vol.Size); err != nil { - deltaOps.UpdateRestoreStatus(volDevName, 0, err) + err = volDev.Truncate(vol.Size) + if err != nil { return } } - if err := performIncrementalRestore(ctx, bsDriver, config, srcVolumeName, volDevPath, lastBackup, backup); err != nil { - deltaOps.UpdateRestoreStatus(volDevName, 0, err) + err = performIncrementalRestore(ctx, bsDriver, config, srcVolumeName, volDevPath, lastBackup, backup) + if err != nil { return } - deltaOps.UpdateRestoreStatus(volDevName, PROGRESS_PERCENTAGE_BACKUP_TOTAL, nil) + finalProgress = PROGRESS_PERCENTAGE_BACKUP_TOTAL }() return nil }