From 0299e488b5d28f08daf42eb02aa3d2fd03477d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deluan=20Quint=C3=A3o?= Date: Sun, 22 Dec 2024 16:41:40 -0500 Subject: [PATCH] fix(server): backup and restore issues from the cli (#3579) * fix(server): backup not working from cli Signed-off-by: Deluan * fix(server): make backup-file required for restore Signed-off-by: Deluan --------- Signed-off-by: Deluan --- cmd/backup.go | 4 ++-- db/backup.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) 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,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