diff --git a/cmd/backup-manager/app/backup/manager.go b/cmd/backup-manager/app/backup/manager.go index 648727b29c8..8705918a3c7 100644 --- a/cmd/backup-manager/app/backup/manager.go +++ b/cmd/backup-manager/app/backup/manager.go @@ -331,14 +331,28 @@ func (bm *Manager) performBackup(ctx context.Context, backup *v1alpha1.Backup, d } if backupErr != nil { + // Calculate the backup size for failed backup job + backupSize, err := util.CalcVolSnapBackupSize(ctx, backup.Spec.StorageProvider) + + if err != nil { + klog.Warningf("Failed to calc volume snapshot backup size %d bytes, %v", backupSize, err) + errs = append(errs, err) + } + + backupSizeReadable := humanize.Bytes(uint64(backupSize)) + errs = append(errs, backupErr) klog.Errorf("backup cluster %s data failed, err: %s", bm, backupErr) + uerr := bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{ Type: v1alpha1.BackupFailed, Status: corev1.ConditionTrue, Reason: "BackupDataToRemoteFailed", Message: backupErr.Error(), - }, nil) + }, &controller.BackupUpdateStatus{ + BackupSize: &backupSize, + BackupSizeReadable: &backupSizeReadable, + }) errs = append(errs, uerr) return errorutils.NewAggregate(errs) } diff --git a/cmd/backup-manager/app/util/backup_size.go b/cmd/backup-manager/app/util/backup_size.go index 35e60249dcb..281f106df1a 100644 --- a/cmd/backup-manager/app/util/backup_size.go +++ b/cmd/backup-manager/app/util/backup_size.go @@ -214,7 +214,7 @@ func calcBackupSize(ctx context.Context, volumes map[string]string) (uint64, err snapshotId := id // sort snapshots by timestamp workerPool.ApplyOnErrorGroup(eg, func() error { - snapSize, apiReq, err := initialSnapshotSize(snapshotId) + snapSize, apiReq, err := calculateSnapshotSize(snapshotId) if err != nil { return err } @@ -234,9 +234,8 @@ func calcBackupSize(ctx context.Context, volumes map[string]string) (uint64, err return backupSize, nil } -// initialSnapshotSize calculate size of an initial snapshot in bytes by listing its blocks. -// initial snapshot always a ful backup of volume -func initialSnapshotSize(snapshotId string) (uint64, uint64, error) { +// calculateSnapshotSize calculate size of an snapshot in bytes by listing its blocks. +func calculateSnapshotSize(snapshotId string) (uint64, uint64, error) { var snapshotSize uint64 var numApiReq uint64 ebsSession, err := util.NewEBSSession(util.CloudAPIConcurrency) diff --git a/pkg/backup/util/remote.go b/pkg/backup/util/remote.go index c0551d7e32c..6125375d32d 100644 --- a/pkg/backup/util/remote.go +++ b/pkg/backup/util/remote.go @@ -215,7 +215,7 @@ type BatchDeleteObjectsResult struct { Errors []ObjectError } -// BatchDeleteObjects delete mutli objects +// BatchDeleteObjects delete multi objects // // Depending on storage type, it use function 'BatchDeleteObjectsOfS3' or 'BatchDeleteObjectsConcurrently' func (b *StorageBackend) BatchDeleteObjects(ctx context.Context, objs []*blob.ListObject, opt v1alpha1.BatchDeleteOption) *BatchDeleteObjectsResult {