Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions agent/app/service/snapshot_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ func handleDownloadSnapshot(itemHelper *snapRecoverHelper, snap model.Snapshot,
itemHelper.Task.LogStart(i18n.GetMsgByKey("RecoverDownload"))

account, client, err := NewBackupClientWithID(snap.DownloadAccountID)
itemHelper.Task.LogWithStatus(i18n.GetWithName("RecoverDownloadAccount", fmt.Sprintf("%s - %s", account.Type, account.Name)), err)
if err != nil {
itemHelper.Task.LogWithStatus(i18n.GetWithName("RecoverDownloadAccount", "-"), err)
return err
}
itemHelper.Task.LogWithStatus(i18n.GetWithName("RecoverDownloadAccount", fmt.Sprintf("%s - %s", account.Type, account.Name)), nil)
targetPath := ""
if len(account.BackupPath) != 0 {
targetPath = path.Join(account.BackupPath, fmt.Sprintf("system_snapshot/%s.tar.gz", snap.Name))
Expand All @@ -259,11 +263,23 @@ func handleDownloadSnapshot(itemHelper *snapRecoverHelper, snap model.Snapshot,
}
filePath := fmt.Sprintf("%s/%s.tar.gz", targetDir, snap.Name)
_ = os.RemoveAll(filePath)
_, err = client.Download(targetPath, filePath)
err = prepareSnapshotRecoverFile(account.Type, targetPath, filePath, func() error {
_, downloadErr := client.Download(targetPath, filePath)
return downloadErr
})
itemHelper.Task.LogWithStatus(i18n.GetMsgByKey("Download"), err)
return err
}

func prepareSnapshotRecoverFile(accountType, sourcePath, targetPath string, download func() error) error {
if accountType == constant.Local {
if err := os.Link(sourcePath, targetPath); err == nil {
return nil
}
}
return download()
Comment on lines +274 to +280
}

func backupBeforeRecover(name string, itemHelper *snapRecoverHelper) error {
itemHelper.Task.Log("---------------------- 3 / 11 ----------------------")
itemHelper.Task.LogStart(i18n.GetMsgByKey("BackupBeforeRecover"))
Expand Down
Loading