mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: diskbackup fail to syncstatus on offline backend (#23763)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -201,7 +201,7 @@ func DoInstancePackBackup(ctx context.Context, backupInfo SStoragePackInstanceBa
|
||||
} else {
|
||||
finalPackageFileName = fmt.Sprintf("%s-%d.tar", backupInfo.PackageName, tried)
|
||||
}
|
||||
exists, err := backupStorage.IsBackupInstanceExists(finalPackageFileName)
|
||||
exists, _, err := backupStorage.IsBackupInstanceExists(finalPackageFileName)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "IsBackupInstanceExists")
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ type IBackupStorage interface {
|
||||
// 删除备份
|
||||
RemoveBackup(ctx context.Context, backupId string) error
|
||||
// 备份是否存在
|
||||
IsBackupExists(backupId string) (bool, error)
|
||||
IsBackupExists(backupId string) (bool, string, error)
|
||||
|
||||
// 从指定路径拷贝主机备份文件到备份存储
|
||||
SaveBackupInstanceFrom(ctx context.Context, srcFilename string, bakcupInstanceId string) error
|
||||
@@ -43,7 +43,7 @@ type IBackupStorage interface {
|
||||
// 删除备份
|
||||
RemoveBackupInstance(ctx context.Context, backupInstanceId string) error
|
||||
// 备份是否存在
|
||||
IsBackupInstanceExists(backupInstanceId string) (bool, error)
|
||||
IsBackupInstanceExists(backupInstanceId string) (bool, string, error)
|
||||
|
||||
// ConvertTo(destPath string, format qemuimgfmt.TImageFormat, backupId string) error
|
||||
// ConvertFrom(srcPath string, format qemuimgfmt.TImageFormat, backupId string) (int, error)
|
||||
|
||||
@@ -194,31 +194,34 @@ func (s *SNFSBackupStorage) removeFile(ctx context.Context, id string, getPathFu
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SNFSBackupStorage) IsBackupExists(backupId string) (bool, error) {
|
||||
func (s *SNFSBackupStorage) IsBackupExists(backupId string) (bool, string, error) {
|
||||
return s.isFileExists(backupId, s.getBackupDiskPath)
|
||||
}
|
||||
|
||||
func (s *SNFSBackupStorage) IsBackupInstanceExists(backupId string) (bool, error) {
|
||||
func (s *SNFSBackupStorage) IsBackupInstanceExists(backupId string) (bool, string, error) {
|
||||
return s.isFileExists(backupId, s.getBackupInstancePath)
|
||||
}
|
||||
|
||||
func (s *SNFSBackupStorage) isFileExists(id string, getPathFunc func(id string) string) (bool, error) {
|
||||
func (s *SNFSBackupStorage) isFileExists(id string, getPathFunc func(id string) string) (bool, string, error) {
|
||||
err := s.checkAndMount()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "unable to checkAndMount")
|
||||
if errors.Cause(err) == ErrorBackupStorageOffline {
|
||||
return false, err.Error(), nil
|
||||
}
|
||||
return false, "", errors.Wrap(err, "unable to checkAndMount")
|
||||
}
|
||||
defer s.unMount()
|
||||
|
||||
filename := getPathFunc(id)
|
||||
return fileutils2.Exists(filename), nil
|
||||
return fileutils2.Exists(filename), "", nil
|
||||
}
|
||||
|
||||
func (s *SNFSBackupStorage) IsOnline() (bool, string, error) {
|
||||
err := s.checkAndMount()
|
||||
if errors.Cause(err) == ErrorBackupStorageOffline {
|
||||
return false, err.Error(), nil
|
||||
}
|
||||
if err != nil {
|
||||
if errors.Cause(err) == ErrorBackupStorageOffline {
|
||||
return false, err.Error(), nil
|
||||
}
|
||||
return false, "", err
|
||||
}
|
||||
s.unMount()
|
||||
|
||||
@@ -178,27 +178,27 @@ func (s *SObjectBackupStorage) removeObject(ctx context.Context, id string, getK
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SObjectBackupStorage) IsBackupExists(backupId string) (bool, error) {
|
||||
func (s *SObjectBackupStorage) IsBackupExists(backupId string) (bool, string, error) {
|
||||
return s.isObjectExists(backupId, s.getBackupKey)
|
||||
}
|
||||
|
||||
func (s *SObjectBackupStorage) IsBackupInstanceExists(backupId string) (bool, error) {
|
||||
func (s *SObjectBackupStorage) IsBackupInstanceExists(backupId string) (bool, string, error) {
|
||||
return s.isObjectExists(backupId, s.getBackupInstanceKey)
|
||||
}
|
||||
|
||||
func (s *SObjectBackupStorage) isObjectExists(id string, getKeyFunc func(string) string) (bool, error) {
|
||||
func (s *SObjectBackupStorage) isObjectExists(id string, getKeyFunc func(string) string) (bool, string, error) {
|
||||
bucket, err := s.getBucket()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "getBucket")
|
||||
return false, "", errors.Wrap(err, "getBucket")
|
||||
}
|
||||
_, err = cloudprovider.GetIObject(bucket, getKeyFunc(id))
|
||||
if err != nil {
|
||||
if errors.Cause(err) == errors.ErrNotFound {
|
||||
return false, nil
|
||||
return false, "", nil
|
||||
}
|
||||
return false, errors.Wrap(err, "GetIObject")
|
||||
return false, "", errors.Wrap(err, "GetIObject")
|
||||
}
|
||||
return true, nil
|
||||
return true, "", nil
|
||||
}
|
||||
|
||||
func (s *SObjectBackupStorage) IsOnline() (bool, string, error) {
|
||||
|
||||
@@ -276,7 +276,7 @@ func storageSyncBackup(ctx context.Context, w http.ResponseWriter, r *http.Reque
|
||||
hostutils.Response(ctx, w, err)
|
||||
return
|
||||
}
|
||||
exist, err := backupStorage.IsBackupExists(backupId)
|
||||
exist, reason, err := backupStorage.IsBackupExists(backupId)
|
||||
if err != nil {
|
||||
hostutils.Response(ctx, w, err)
|
||||
return
|
||||
@@ -287,11 +287,13 @@ func storageSyncBackup(ctx context.Context, w http.ResponseWriter, r *http.Reque
|
||||
)
|
||||
if exist {
|
||||
status = compute.BACKUP_EXIST
|
||||
} else if !exist && err == nil {
|
||||
status = compute.BACKUP_NOT_EXIST
|
||||
} else {
|
||||
log.Errorf("fetch snapshot exist failed %s", err)
|
||||
status = compute.BACKUP_STATUS_UNKNOWN
|
||||
if len(reason) == 0 {
|
||||
status = compute.BACKUP_NOT_EXIST
|
||||
} else {
|
||||
log.Errorf("fetch snapshot exist failed reason:%s", reason)
|
||||
status = compute.BACKUP_STATUS_UNKNOWN
|
||||
}
|
||||
}
|
||||
ret.Set("status", jsonutils.NewString(status))
|
||||
hostutils.Response(ctx, w, ret)
|
||||
|
||||
Reference in New Issue
Block a user