Skip to content

Commit

Permalink
fix(db): fix missing portainer.edb in backups when encrypted portaine…
Browse files Browse the repository at this point in the history
…r db is used [EE-6417] (#11885)
  • Loading branch information
hookenz committed Jun 6, 2024
1 parent 4a7f96c commit 62c2bf8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func CreateBackupArchive(password string, gate *offlinegate.OfflineGate, datasto
}

func backupDb(backupDirPath string, datastore dataservices.DataStore) error {
_, err := datastore.Backup(filepath.Join(backupDirPath, "portainer.db"))
dbFileName := datastore.Connection().GetDatabaseFileName()
_, err := datastore.Backup(filepath.Join(backupDirPath, dbFileName))
return err
}

Expand Down
1 change: 1 addition & 0 deletions api/dataservices/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type (
}

DataStore interface {
Connection() portainer.Connection
Open() (newStore bool, err error)
Init() error
Close() error
Expand Down
9 changes: 8 additions & 1 deletion api/internal/testhelpers/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/database"
"github.com/portainer/portainer/api/dataservices"
"github.com/portainer/portainer/api/dataservices/errors"
)
Expand Down Expand Up @@ -34,6 +35,7 @@ type testDatastore struct {
version dataservices.VersionService
webhook dataservices.WebhookService
pendingActionsService dataservices.PendingActionsService
connection portainer.Connection
}

func (d *testDatastore) Backup(path string) (string, error) { return "", nil }
Expand Down Expand Up @@ -88,6 +90,10 @@ func (d *testDatastore) PendingActions() dataservices.PendingActionsService {
return d.pendingActionsService
}

func (d *testDatastore) Connection() portainer.Connection {
return d.connection
}

func (d *testDatastore) IsErrObjectNotFound(e error) bool {
return false
}
Expand All @@ -105,7 +111,8 @@ type datastoreOption = func(d *testDatastore)
// NewDatastore creates new instance of testDatastore.
// Will apply options before returning, opts will be applied from left to right.
func NewDatastore(options ...datastoreOption) *testDatastore {
d := testDatastore{}
conn, _ := database.NewDatabase("boltdb", "", nil)
d := testDatastore{connection: conn}
for _, o := range options {
o(&d)
}
Expand Down

0 comments on commit 62c2bf8

Please sign in to comment.