mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-24 12:32:55 +08:00
feat(region): check backup storage status before making backup
This commit is contained in:
@@ -16,6 +16,7 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
@@ -221,10 +222,23 @@ func (dm *SDiskBackupManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
if disk.Status != api.DISK_READY {
|
||||
return input, httperrors.NewInvalidStatusError("disk %s status is not %s", disk.Name, api.DISK_READY)
|
||||
}
|
||||
_, err = validators.ValidateModel(userCred, BackupStorageManager, &input.BackupStorageId)
|
||||
ibs, err := BackupStorageManager.FetchByIdOrName(userCred, input.BackupStorageId)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return input, httperrors.NewResourceNotFoundError2(BackupStorageManager.Keyword(), input.BackupStorageId)
|
||||
}
|
||||
if errors.Cause(err) == sqlchemy.ErrDuplicateEntry {
|
||||
return input, httperrors.NewDuplicateResourceError(BackupStorageManager.Keyword(), input.BackupStorageId)
|
||||
}
|
||||
return input, httperrors.NewGeneralError(err)
|
||||
}
|
||||
if err != nil {
|
||||
return input, err
|
||||
}
|
||||
bs := ibs.(*SBackupStorage)
|
||||
if bs.Status != api.BACKUPSTORAGE_STATUS_ONLINE {
|
||||
return input, httperrors.NewForbiddenError("can't backup guest to backup storage with status %s", bs.Status)
|
||||
}
|
||||
storage, err := disk.GetStorage()
|
||||
if err != nil {
|
||||
return input, errors.Wrapf(err, "unable to get storage of disk %s", disk.GetId())
|
||||
|
||||
@@ -4748,9 +4748,19 @@ func (self *SGuest) PerformInstanceBackup(ctx context.Context, userCred mcclient
|
||||
if backupStorageId == "" {
|
||||
return nil, httperrors.NewMissingParameterError("backup_storage_id")
|
||||
}
|
||||
_, err = BackupStorageManager.FetchById(backupStorageId)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewInputParameterError("unkown backup_storage_id %s", backupStorageId)
|
||||
ibs, err := BackupStorageManager.FetchByIdOrName(userCred, backupStorageId)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, httperrors.NewResourceNotFoundError2(BackupStorageManager.Keyword(), backupStorageId)
|
||||
}
|
||||
if errors.Cause(err) == sqlchemy.ErrDuplicateEntry {
|
||||
return nil, httperrors.NewDuplicateResourceError(BackupStorageManager.Keyword(), backupStorageId)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
bs := ibs.(*SBackupStorage)
|
||||
if bs.Status != api.BACKUPSTORAGE_STATUS_ONLINE {
|
||||
return nil, httperrors.NewForbiddenError("can't backup guest to backup storage with status %s", bs.Status)
|
||||
}
|
||||
instanceBackup, err := InstanceBackupManager.CreateInstanceBackup(ctx, userCred, self, name, backupStorageId)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user