mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-01 19:47:37 +03:00
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:
parent
630c304080
commit
0299e488b5
2 changed files with 8 additions and 8 deletions
|
@ -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)
|
||||
|
|
12
db/backup.go
12
db/backup.go
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue