fix(server): backup and restore issues from the cli (#3579)

* fix(server): backup not working from cli

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(server): make backup-file required for restore

Signed-off-by: Deluan <deluan@navidrome.org>

---------

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan Quintão 2024-12-22 16:41:40 -05:00 committed by GitHub
parent 630c304080
commit 0299e488b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View file

@ -33,7 +33,7 @@ func init() {
restoreCommand.Flags().StringVarP(&restorePath, "backup-file", "b", "", "path of backup database to restore")
restoreCommand.Flags().BoolVarP(&force, "force", "f", false, "bypass restore warning")
_ = restoreCommand.MarkFlagRequired("backup-path")
_ = restoreCommand.MarkFlagRequired("backup-file")
backupRoot.AddCommand(restoreCommand)
}
@ -178,7 +178,7 @@ func runRestore(ctx context.Context) {
start := time.Now()
err := db.Restore(ctx, restorePath)
if err != nil {
log.Fatal("Error backing up database", "backup path", conf.Server.BasePath, err)
log.Fatal("Error restoring database", "backup path", conf.Server.BasePath, err)
}
elapsed := time.Since(start)

View file

@ -34,18 +34,18 @@ func backupPath(t time.Time) string {
func backupOrRestore(ctx context.Context, isBackup bool, path string) error {
// heavily inspired by https://codingrabbits.dev/posts/go_and_sqlite_backup_and_maybe_restore/
backupDb, err := sql.Open(Driver, path)
if err != nil {
return err
}
defer backupDb.Close()
existingConn, err := Db().Conn(ctx)
if err != nil {
return err
}
defer existingConn.Close()
backupDb, err := sql.Open(Driver, path)
if err != nil {
return err
}
defer backupDb.Close()
backupConn, err := backupDb.Conn(ctx)
if err != nil {
return err