revert: separation of write and read DBs
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
+17
-3
@@ -32,7 +32,7 @@ func backupPath(t time.Time) string {
|
||||
)
|
||||
}
|
||||
|
||||
func (d *db) backupOrRestore(ctx context.Context, isBackup bool, path string) error {
|
||||
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 {
|
||||
@@ -40,7 +40,7 @@ func (d *db) backupOrRestore(ctx context.Context, isBackup bool, path string) er
|
||||
}
|
||||
defer backupDb.Close()
|
||||
|
||||
existingConn, err := d.writeDB.Conn(ctx)
|
||||
existingConn, err := Db().Conn(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -100,7 +100,21 @@ func (d *db) backupOrRestore(ctx context.Context, isBackup bool, path string) er
|
||||
return err
|
||||
}
|
||||
|
||||
func prune(ctx context.Context) (int, error) {
|
||||
func Backup(ctx context.Context) (string, error) {
|
||||
destPath := backupPath(time.Now())
|
||||
err := backupOrRestore(ctx, true, destPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return destPath, nil
|
||||
}
|
||||
|
||||
func Restore(ctx context.Context, path string) error {
|
||||
return backupOrRestore(ctx, false, path)
|
||||
}
|
||||
|
||||
func Prune(ctx context.Context) (int, error) {
|
||||
files, err := os.ReadDir(conf.Server.Backup.Path)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("unable to read database backup entries: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user