Skip to content

Commit

Permalink
Merge pull request #663 from Scalingo/fix/657/backups_download
Browse files Browse the repository at this point in the history
fix(backup-download) Now download the last successful backup
  • Loading branch information
EtienneM authored Jun 3, 2021
2 parents c86a823 + 65b1bc1 commit da7032d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* bump github.com/fatih/color from 1.11.0 to 1.12.0: add support for `NO_COLOR` environment variable.
* bump github.com/briandowns/spinner from 1.12.0 to 1.13.0
* fix(backup-download) Now download the last successful backup [#663](https://github.com/Scalingo/cli/pull/663)

### 1.20.2

Expand Down
19 changes: 16 additions & 3 deletions db/backup_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/Scalingo/cli/config"
"github.com/Scalingo/go-scalingo/v4"
"github.com/Scalingo/go-scalingo/v4/debug"
"github.com/briandowns/spinner"
"github.com/cheggaaa/pb"
Expand Down Expand Up @@ -48,10 +49,13 @@ func DownloadBackup(app, addon, backupID string, opts DownloadBackupOpts) error
return errgo.Notef(err, "fail to get the most recent backup")
}
if len(backups) == 0 {
return errgo.New("This addon has no backup")
return errgo.New("this addon has no backup")
}
backupID = backups[0].ID
fmt.Fprintln(logWriter, "-----> Selected the most recent backup")
backupID, err = getLastSuccessfulBackup(backups)
if err != nil {
return errgo.Notef(err, "fail to get a successful backup")
}
fmt.Fprintln(logWriter, "-----> Selected the most recent successful backup")
}

// Start a spinner when loading metadatas
Expand Down Expand Up @@ -131,3 +135,12 @@ func isDir(path string) bool {

return s.IsDir()
}

func getLastSuccessfulBackup(backups []scalingo.Backup) (string, error) {
for _, backup := range backups {
if backup.Status == scalingo.BackupStatusDone {
return backup.ID, nil
}
}
return "", errgo.New("can't find any successful backup")
}

0 comments on commit da7032d

Please sign in to comment.