1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00

fix(backups): fix rollback feature [EE-6367] (#10691)

This commit is contained in:
Matt Hook 2023-11-28 11:12:17 +13:00 committed by GitHub
parent 76bcdfa2b8
commit db46dc553f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 92 deletions

View file

@ -65,7 +65,7 @@ type BackupOptions struct {
// - db rollback
func getBackupRestoreOptions(backupDir string) *BackupOptions {
return &BackupOptions{
BackupDir: backupDir, //connection.commonBackupDir(),
BackupDir: backupDir,
BackupFileName: beforePortainerVersionUpgradeBackup,
}
}
@ -76,12 +76,12 @@ func (store *Store) Backup(version *models.Version) (string, error) {
return store.backupWithOptions(nil)
}
return store.backupWithOptions(&BackupOptions{
Version: version.SchemaVersion,
})
backupOptions := getBackupRestoreOptions(store.commonBackupDir())
backupOptions.Version = version.SchemaVersion
return store.backupWithOptions(backupOptions)
}
func (store *Store) setupOptions(options *BackupOptions) *BackupOptions {
func (store *Store) setDefaultBackupOptions(options *BackupOptions) *BackupOptions {
if options == nil {
options = &BackupOptions{}
}
@ -110,7 +110,7 @@ func (store *Store) backupWithOptions(options *BackupOptions) (string, error) {
store.createBackupFolders()
options = store.setupOptions(options)
options = store.setDefaultBackupOptions(options)
dbPath := store.databasePath()
if err := store.Close(); err != nil {
@ -139,20 +139,18 @@ func (store *Store) backupWithOptions(options *BackupOptions) (string, error) {
// - default: restore latest from current edition
// - restore a specific
func (store *Store) restoreWithOptions(options *BackupOptions) error {
options = store.setupOptions(options)
options = store.setDefaultBackupOptions(options)
// Check if backup file exist before restoring
_, err := os.Stat(options.BackupPath)
if os.IsNotExist(err) {
log.Error().Str("path", options.BackupPath).Err(err).Msg("backup file to restore does not exist %s")
log.Error().Str("path", options.BackupPath).Err(err).Msg("backup file to restore does not exist")
return err
}
err = store.Close()
if err != nil {
log.Error().Err(err).Msg("error while closing store before restore")
return err
}
@ -170,7 +168,7 @@ func (store *Store) restoreWithOptions(options *BackupOptions) error {
func (store *Store) removeWithOptions(options *BackupOptions) error {
log.Info().Msg("removing DB backup")
options = store.setupOptions(options)
options = store.setDefaultBackupOptions(options)
_, err := os.Stat(options.BackupPath)
if os.IsNotExist(err) {