Skip to content

Commit

Permalink
*: report the backup size for failed backup
Browse files Browse the repository at this point in the history
Signed-off-by: BornChanger <dawn_catcher@126.com>
  • Loading branch information
BornChanger committed May 12, 2023
1 parent c1cf6e2 commit ff11f9a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
16 changes: 15 additions & 1 deletion cmd/backup-manager/app/backup/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/backup-manager/app/util/backup_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/backup/util/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ff11f9a

Please sign in to comment.