Skip to content

🎧 Your Personal Streaming Service

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

Deluan Quintão0299e488b5d2
diff --git a/cmd/backup.go b/cmd/backup.go
index cd9055afa..ab73f7537 100644
--- a/cmd/backup.go
+++ b/cmd/backup.go
@@ -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)
diff --git a/db/backup.go b/db/backup.go
index 86df1f459..050da605e 100644
--- a/db/backup.go
+++ b/db/backup.go
@@ -34,17 +34,17 @@ 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)
+ existingConn, err := Db().Conn(ctx)
if err != nil {
return err
}
- defer backupDb.Close()
+ defer existingConn.Close()
- existingConn, err := Db().Conn(ctx)
+ backupDb, err := sql.Open(Driver, path)
if err != nil {
return err
}
- defer existingConn.Close()
+ defer backupDb.Close()
backupConn, err := backupDb.Conn(ctx)
if err != nil {