mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
close db before restore. fix log (#10826)
This commit is contained in:
parent
e4d71d858d
commit
0b9407f0a6
2 changed files with 5 additions and 2 deletions
|
@ -144,6 +144,8 @@ func (connection *DbConnection) Open() error {
|
||||||
// Close closes the BoltDB database.
|
// Close closes the BoltDB database.
|
||||||
// Safe to being called multiple times.
|
// Safe to being called multiple times.
|
||||||
func (connection *DbConnection) Close() error {
|
func (connection *DbConnection) Close() error {
|
||||||
|
log.Info().Msg("closing PortainerDB")
|
||||||
|
|
||||||
if connection.DB != nil {
|
if connection.DB != nil {
|
||||||
return connection.DB.Close()
|
return connection.DB.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,11 +43,12 @@ func (store *Store) Restore() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *Store) RestoreFromFile(backupFilename string) error {
|
func (store *Store) RestoreFromFile(backupFilename string) error {
|
||||||
|
store.Close()
|
||||||
if err := store.fileService.Copy(backupFilename, store.connection.GetDatabaseFilePath(), true); err != nil {
|
if err := store.fileService.Copy(backupFilename, store.connection.GetDatabaseFilePath(), true); err != nil {
|
||||||
return fmt.Errorf("unable to restore backup file %q. err: %w", backupFilename, err)
|
return fmt.Errorf("unable to restore backup file %q. err: %w", backupFilename, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Str("from", store.connection.GetDatabaseFilePath()).Str("to", backupFilename).Msgf("database restored")
|
log.Info().Str("from", backupFilename).Str("to", store.connection.GetDatabaseFilePath()).Msgf("database restored")
|
||||||
|
|
||||||
_, err := store.Open()
|
_, err := store.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -61,7 +62,7 @@ func (store *Store) RestoreFromFile(backupFilename string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
editionLabel := portainer.SoftwareEdition(version.Edition).GetEditionLabel()
|
editionLabel := portainer.SoftwareEdition(version.Edition).GetEditionLabel()
|
||||||
log.Info().Str("version", version.SchemaVersion).Msgf("Restored database version: Portainer %s %s ", editionLabel, version.SchemaVersion)
|
log.Info().Msgf("Restored database version: Portainer %s %s", editionLabel, version.SchemaVersion)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue