Phase C1: gate db.Backup() on GOGOBEE_BACKUP_DIR

Audit flagged C1 as "Backup() unwired" — actually
adventure_scheduler's dailyReset has been calling it every
midnight. The real gap was that Backup() always ran, always
to dataPath/backups, with no way for dev environments to opt
out.

Now: env var unset → no-op + debug log. Env var set → that
directory is the destination. Existing scheduler call site
unchanged; it cleanly no-ops in dev.
This commit is contained in:
prosolis
2026-05-15 07:50:11 -07:00
parent b4b1e0ee29
commit ce2f59c332

View File

@@ -463,8 +463,16 @@ func CacheSet(key, data string) {
// Backup creates a consistent snapshot of the database using VACUUM INTO. // Backup creates a consistent snapshot of the database using VACUUM INTO.
// Keeps the last 7 daily backups, deleting older ones. // Keeps the last 7 daily backups, deleting older ones.
//
// Gated on the GOGOBEE_BACKUP_DIR env var: when unset, this is a no-op so
// dev environments don't accumulate snapshots. When set, that directory is
// used as the backup destination.
func Backup() error { func Backup() error {
backupDir := filepath.Join(dataPath, "backups") backupDir := os.Getenv("GOGOBEE_BACKUP_DIR")
if backupDir == "" {
slog.Debug("backup skipped: GOGOBEE_BACKUP_DIR unset")
return nil
}
if err := os.MkdirAll(backupDir, 0o755); err != nil { if err := os.MkdirAll(backupDir, 0o755); err != nil {
return fmt.Errorf("create backup dir: %w", err) return fmt.Errorf("create backup dir: %w", err)
} }