diff --git a/apis/stash/v1beta1/backup_session_types.go b/apis/stash/v1beta1/backup_session_types.go index d6bd9467e..e3e7d7b96 100644 --- a/apis/stash/v1beta1/backup_session_types.go +++ b/apis/stash/v1beta1/backup_session_types.go @@ -151,7 +151,7 @@ type HostBackupStats struct { // Snapshots specifies the stats of individual snapshots that has been taken for this host in current backup session // +optional Snapshots []SnapshotStats `json:"snapshots,omitempty"` - // Duration indicates total time taken to complete backup for this hosts + // Duration indicates total time taken to complete backup for this host // +optional Duration string `json:"duration,omitempty"` // Error indicates string value of error in case of backup failure diff --git a/apis/stash/v1beta1/openapi_generated.go b/apis/stash/v1beta1/openapi_generated.go index 2936d9187..4e0e893b9 100644 --- a/apis/stash/v1beta1/openapi_generated.go +++ b/apis/stash/v1beta1/openapi_generated.go @@ -21512,7 +21512,7 @@ func schema_apimachinery_apis_stash_v1beta1_HostBackupStats(ref common.Reference }, "duration": { SchemaProps: spec.SchemaProps{ - Description: "Duration indicates total time taken to complete backup for this hosts", + Description: "Duration indicates total time taken to complete backup for this host", Type: []string{"string"}, Format: "", }, diff --git a/crds/stash.appscode.com_backupsessions.yaml b/crds/stash.appscode.com_backupsessions.yaml index 3f67a7913..51bfa6527 100644 --- a/crds/stash.appscode.com_backupsessions.yaml +++ b/crds/stash.appscode.com_backupsessions.yaml @@ -252,7 +252,7 @@ spec: properties: duration: description: Duration indicates total time taken to complete - backup for this hosts + backup for this host type: string error: description: Error indicates string value of error in diff --git a/openapi/swagger.json b/openapi/swagger.json index 55104e1b0..149eafaee 100644 --- a/openapi/swagger.json +++ b/openapi/swagger.json @@ -10247,7 +10247,7 @@ "type": "object", "properties": { "duration": { - "description": "Duration indicates total time taken to complete backup for this hosts", + "description": "Duration indicates total time taken to complete backup for this host", "type": "string" }, "error": { diff --git a/pkg/restic/backup.go b/pkg/restic/backup.go index d5d06437c..ae467551e 100644 --- a/pkg/restic/backup.go +++ b/pkg/restic/backup.go @@ -90,20 +90,20 @@ func (w *ResticWrapper) RunParallelBackup(backupOptions []BackupOptions, targetR }() // sh field in ResticWrapper is a pointer. we must not use same w in multiple go routine. - // otherwise they might enter in a racing condition. + // otherwise they might enter in racing condition. nw := w.Copy() hostStats, err := nw.runBackup(opt) + hostStats.Duration = time.Since(startTime).String() if err != nil { - // acquire lock to make sure no other go routine is writing to backupErr + hostStats.Phase = api_v1beta1.HostBackupFailed + hostStats.Error = err.Error() mu.Lock() backupErrs = append(backupErrs, err) mu.Unlock() - return + } else { + hostStats.Phase = api_v1beta1.HostBackupSucceeded } - hostStats.Duration = time.Since(startTime).String() - hostStats.Phase = api_v1beta1.HostBackupSucceeded - // add hostStats to backupOutput. use lock to avoid racing condition. mu.Lock() backupOutput.upsertHostBackupStats(hostStats) @@ -114,10 +114,7 @@ func (w *ResticWrapper) RunParallelBackup(backupOptions []BackupOptions, targetR // wait for all the go routines to complete wg.Wait() - if backupErrs != nil { - return nil, errors.NewAggregate(backupErrs) - } - return backupOutput, nil + return backupOutput, errors.NewAggregate(backupErrs) } func (w *ResticWrapper) runBackup(backupOption BackupOptions) (api_v1beta1.HostBackupStats, error) { diff --git a/pkg/restic/restore.go b/pkg/restic/restore.go index f776f6809..921cd2c89 100644 --- a/pkg/restic/restore.go +++ b/pkg/restic/restore.go @@ -195,27 +195,27 @@ func (w *ResticWrapper) ParallelDump(dumpOptions []DumpOptions, targetRef api_v1 opt.SourceHost = opt.Host } + hostStats := api_v1beta1.HostRestoreStats{ + Hostname: opt.Host, + } // run restore _, err := nw.DumpOnce(opt) + hostStats.Duration = time.Since(startTime).String() if err != nil { + hostStats.Phase = api_v1beta1.HostRestoreFailed + hostStats.Error = err.Error() mu.Lock() restoreErrs = append(restoreErrs, err) mu.Unlock() - return + } else { + hostStats.Phase = api_v1beta1.HostRestoreSucceeded } - hostStats := api_v1beta1.HostRestoreStats{ - Hostname: opt.Host, - } - hostStats.Duration = time.Since(startTime).String() - hostStats.Phase = api_v1beta1.HostRestoreSucceeded - - // add hostStats to restoreOutput + // add hostStats to restoreOutput. use lock to avoid racing condition. mu.Lock() restoreOutput.upsertHostRestoreStats(hostStats) mu.Unlock() }(dumpOptions[i], time.Now()) } - // wait for all the go routines to complete wg.Wait()