Files
tiny-forge/plans/backup-management/phase-1-backup-engine.md
T
alexei.dolgolyov a9c7775bb7 feat: configuration backup management with manual and auto backup
Add backup/restore functionality for the SQLite database. Users can
trigger manual backups, configure automatic backups on an interval
with retention policies, list/download/delete backups, and restore
from any backup.

- Backup engine using VACUUM INTO (safe with WAL mode)
- Backup metadata tracked in DB, files stored in DATA_DIR/backups/
- Settings: backup_enabled, backup_interval_hours, backup_retention_count
- API: POST/GET/DELETE /api/backups, download, restore endpoints
- Autobackup via cron scheduler with configurable interval
- Retention: prune on startup, after each backup (manual and auto)
- Orphan cleanup: removes backup files without metadata on startup
- Restore: replaces DB and triggers graceful server shutdown
- Settings UI: /settings/backup with toggle, interval, retention config
- Backup list with download, delete, restore actions
- i18n: English and Russian translations
2026-04-02 15:32:15 +03:00

1.9 KiB

Phase 1: Backup Engine & Settings

Status: Not Started Parent plan: PLAN.md Domain: backend

Objective

Create the core backup engine and extend settings to support backup configuration.

Tasks

  • Task 1: Add backup settings fields to Settings model
    • BackupEnabled bool (default false)
    • BackupIntervalHours int (default 24)
    • BackupRetentionCount int (default 10)
  • Task 2: Add migration columns in store.go
  • Task 3: Update GetSettings/UpdateSettings queries
  • Task 4: Create backups metadata table
    • id, filename, size_bytes, backup_type (manual/auto), created_at
  • Task 5: Create internal/backup/engine.go
    • Engine struct with db path, backup dir
    • CreateBackup(backupType string) (Backup, error) — VACUUM INTO timestamped file
    • ListBackups() ([]Backup, error) — read from metadata table
    • GetBackup(id string) (Backup, error)
    • DeleteBackup(id string) error — delete file + metadata
    • RestoreBackup(id string) error — copy backup over main DB
    • DownloadPath(id string) (string, error) — return file path for download
  • Task 6: Create internal/store/backups.go — CRUD for backup metadata
  • Task 7: Create backup directory on engine init (DATA_DIR/backups/)

Files to Modify/Create

  • internal/store/models.go — add Backup struct, extend Settings
  • internal/store/store.go — add migration + backups table
  • internal/store/settings.go — update queries
  • internal/store/backups.go — backup metadata CRUD
  • internal/backup/engine.go — core backup logic

Acceptance Criteria

  • Backup engine can create a backup file via VACUUM INTO
  • Backup metadata stored in DB
  • Backup files stored in DATA_DIR/backups/
  • Settings include backup configuration fields
  • Delete removes both file and metadata

Handoff to Next Phase