fix(backup): back up the contacts (logbook), not just the settings db
Since the logbook was split into its own SQLite file, backup.Run was still snapshotting a.db (the settings/config database) — so the scheduled and manual backups silently stopped including the QSOs. The operator was backing up config and thinking it was their log. Track the resolved logbook file path (a.logDbPath, set in connectLogbook) and route the backup through a new runConfiguredBackup: the CONTACTS become the primary "opslog-*" backup (the logbook file on SQLite, an ADIF export on MySQL), and the settings/config db is snapshotted separately as "opslogcfg-*" so nothing is lost. backup.Run takes a name prefix; the two sets rotate independently.
This commit is contained in:
@@ -44,7 +44,7 @@ func DefaultFolder(dataDir string) string {
|
||||
// statement (no torn-copy window while the app keeps writing), and compacts
|
||||
// the destination as a bonus. It replaces the old "checkpoint + raw io.Copy",
|
||||
// which could capture a half-written page during a concurrent write.
|
||||
func Run(ctx context.Context, dbConn *sql.DB, dbPath, folder string, rotation int, doZip bool) (string, error) {
|
||||
func Run(ctx context.Context, dbConn *sql.DB, dbPath, folder string, rotation int, doZip bool, prefix string) (string, error) {
|
||||
if dbConn == nil {
|
||||
return "", fmt.Errorf("nil db connection")
|
||||
}
|
||||
@@ -54,12 +54,15 @@ func Run(ctx context.Context, dbConn *sql.DB, dbPath, folder string, rotation in
|
||||
if folder == "" {
|
||||
return "", fmt.Errorf("backup folder not set")
|
||||
}
|
||||
if prefix == "" {
|
||||
prefix = "opslog"
|
||||
}
|
||||
if err := os.MkdirAll(folder, 0o755); err != nil {
|
||||
return "", fmt.Errorf("create backup folder: %w", err)
|
||||
}
|
||||
|
||||
stamp := time.Now().Format("2006-01-02")
|
||||
base := fmt.Sprintf("opslog-%s", stamp)
|
||||
base := fmt.Sprintf("%s-%s", prefix, stamp)
|
||||
|
||||
// VACUUM INTO requires a non-existent target → use a temp file, then
|
||||
// move/zip it into place.
|
||||
@@ -92,7 +95,7 @@ func Run(ctx context.Context, dbConn *sql.DB, dbPath, folder string, rotation in
|
||||
}
|
||||
}
|
||||
|
||||
if err := rotate(folder, rotation); err != nil {
|
||||
if err := rotateMatch(folder, rotation, prefix+"-", ".db", ".db.zip"); err != nil {
|
||||
// Rotation errors are non-fatal — the backup itself succeeded.
|
||||
return dstPath, fmt.Errorf("rotate: %w (backup OK at %s)", err, dstPath)
|
||||
}
|
||||
@@ -203,12 +206,6 @@ func copyZipped(src, dst, innerName string) error {
|
||||
return out.Close()
|
||||
}
|
||||
|
||||
// rotate keeps the most recent `keep` SQLite backups (opslog-*.db /
|
||||
// opslog-*.db.zip) and deletes the rest.
|
||||
func rotate(folder string, keep int) error {
|
||||
return rotateMatch(folder, keep, "opslog-", ".db", ".db.zip")
|
||||
}
|
||||
|
||||
// rotateMatch keeps the most recent `keep` files in folder whose name has the
|
||||
// given prefix and one of the given suffixes, deleting older ones. Only matching
|
||||
// files are touched — never unrelated user files in the same folder. The suffix
|
||||
|
||||
Reference in New Issue
Block a user