v0.12.7: mandatory HDD backup, pre-dump, restore for all apps
Fix 1: HDD data backup is now mandatory for all deployed apps. resolveAppBackupPaths() iterates ListDeployedStacks() directly — no longer reads GetAppBackupMap() or checks the Enabled flag. DiscoverAppData() drops backupPrefs parameter; BackupEnabled is set from HasHDDData. Five dead settings methods removed: IsAppBackupEnabled, SetAppBackup, GetAppBackupMap, SetAppBackupBulk, GetAppBackupPrefs. Fix 2: Cross-drive backup now triggers a fresh DB dump (DumpStackDB) before running. DBDumper interface added to crossdrive.go; Manager implements it; SetDBDumper wired in main.go. Non-fatal — proceeds with user data backup even if DB dump fails. Fix 3: Restore dropdown shows ALL deployed apps (not just HDD+enabled). restore.go rewritten: always restores config+DB, adds user data if hasHDD. UI shows restore type banner (full / config+DB / config only) with color-coded styling. Snapshot API clarified for non-HDD apps. Fix 4: "Docker kötetek" → "Konfiguráció" — named volumes are not in the restic backup paths; compose files + app.yaml are what's backed up. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,35 @@
|
|||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
|
### What was just completed (2026-02-18 session 43)
|
||||||
|
- **v0.12.7 — Backup Architecture Overhaul (mandatory HDD backup, pre-dump, restore for all apps):**
|
||||||
|
|
||||||
|
**Fix 1: HDD data backup now mandatory (`backup.go`, `appdata.go`, `settings.go`)**
|
||||||
|
- `resolveAppBackupPaths()` rewrote to iterate ALL deployed stacks via `ListDeployedStacks()` — no longer reads `GetAppBackupMap()` or checks `Enabled` flag
|
||||||
|
- `DiscoverAppData()` signature simplified: dropped `backupPrefs map[string]bool` parameter; `BackupEnabled` is now derived from `HasHDDData` (if app has HDD data, it's always backed up)
|
||||||
|
- `RefreshCache()` updated to call new `DiscoverAppData(m.stackProvider, status.DiscoveredDBs)` signature
|
||||||
|
- 5 dead settings methods deleted: `IsAppBackupEnabled`, `SetAppBackup`, `GetAppBackupMap`, `SetAppBackupBulk`, `GetAppBackupPrefs` — `AppBackupPrefs.Enabled` field kept in struct for backward-compat JSON loading
|
||||||
|
|
||||||
|
**Fix 2: Cross-drive backup triggers fresh DB dump first (`crossdrive.go`, `backup.go`, `main.go`)**
|
||||||
|
- New `DBDumper` interface with `DumpStackDB(ctx, stackName)` in `crossdrive.go`
|
||||||
|
- `CrossDriveRunner` gets `dbDumper` field + `SetDBDumper(d DBDumper)` setter
|
||||||
|
- `Manager.DumpStackDB()` discovers containers for that stack via `DiscoverDatabases()`, runs `DumpAll()`, persists validation cache — same logic as nightly dump but scoped to one stack
|
||||||
|
- `RunAppBackup()` calls `DumpStackDB()` before `ValidateDestination()` — non-fatal on failure (logs warn, proceeds with user data)
|
||||||
|
- `main.go` wires `crossDriveRunner.SetDBDumper(backupMgr)` after both are initialized
|
||||||
|
|
||||||
|
**Fix 3: Restore dropdown shows ALL deployed apps (`backups.html`, `restore.go`, `router.go`)**
|
||||||
|
- `restore.go` rewritten: no `IsAppBackupEnabled()` check; resolves `GetStackComposePath` + `DBDumpDir` + HDD mounts; always restores config+DB, adds user data if `hasHDD`; logs restore type (`config+DB` vs `full (config+DB+userdata)`)
|
||||||
|
- Restore dropdown template: removed `{{if and .HasHDDData .BackupEnabled}}` filter; every app gets an `<option>` with `data-has-hdd` and `data-has-db` attributes
|
||||||
|
- New `#restore-type-info` div added between snapshot selector and warnings
|
||||||
|
- `onRestoreAppChange()` JS updated: reads `data-has-hdd`/`data-has-db` from selected option, shows Hungarian restore type banner (full / config+DB / config only) with color-coded styling
|
||||||
|
- `router.go` `backupSnapshots`: added clarifying comment for non-HDD apps (no filter = all snapshots returned)
|
||||||
|
|
||||||
|
**Fix 4: Honest UI label (`backups.html`)**
|
||||||
|
- "Docker kötetek" renamed to "Konfiguráció" — Docker named volumes at `/var/lib/docker/volumes/` are NOT in the restic backup paths; what's actually backed up is compose files + app.yaml + .felhom.yml
|
||||||
|
|
||||||
|
**CSS: `.restore-info` and `.restore-info-partial` classes added to `style.css`**
|
||||||
|
|
||||||
|
**Files modified (9):** `internal/backup/backup.go`, `internal/backup/appdata.go`, `internal/settings/settings.go`, `internal/backup/crossdrive.go`, `internal/backup/restore.go`, `cmd/controller/main.go`, `internal/web/templates/backups.html`, `internal/web/templates/style.css`, `internal/api/router.go`
|
||||||
|
|
||||||
### What was just completed (2026-02-18 session 42)
|
### What was just completed (2026-02-18 session 42)
|
||||||
- **v0.12.6 — Cross-Drive Backup Rsync Fixes:**
|
- **v0.12.6 — Cross-Drive Backup Rsync Fixes:**
|
||||||
|
|
||||||
|
|||||||
+25
-13
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
A single, lightweight Go container that replaces Portainer + scattered systemd scripts with a unified, Hungarian-language web dashboard for managing Docker Compose stacks, backups, storage, monitoring, and notifications on customer hardware.
|
A single, lightweight Go container that replaces Portainer + scattered systemd scripts with a unified, Hungarian-language web dashboard for managing Docker Compose stacks, backups, storage, monitoring, and notifications on customer hardware.
|
||||||
|
|
||||||
**Current version: v0.12.6**
|
**Current version: v0.12.7**
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -163,7 +163,10 @@ The `/apps/{slug}` page renders hero section, screenshots, setup guide, and opti
|
|||||||
|
|
||||||
### 2. Backup System
|
### 2. Backup System
|
||||||
|
|
||||||
The backup system implements a 3-layer architecture ensuring data safety through redundancy and versioning.
|
The backup system implements a **3-2-1 backup architecture**:
|
||||||
|
1. **Nightly restic (mandatory, same drive)** — DB dumps + config + ALL user data (HDD). Every app with data is backed up automatically. No toggles.
|
||||||
|
2. **Cross-drive backup (opt-in, different device)** — rsync or restic to a secondary physical drive. Protects against drive failure.
|
||||||
|
3. **Remote backup (future)** — offsite copy for disaster recovery.
|
||||||
|
|
||||||
#### Layer 1: Database Dumps (`internal/backup/dbdump.go`)
|
#### Layer 1: Database Dumps (`internal/backup/dbdump.go`)
|
||||||
|
|
||||||
@@ -173,12 +176,14 @@ The backup system implements a 3-layer architecture ensuring data safety through
|
|||||||
- **Validation** after each dump: checks file size, header presence, counts `CREATE TABLE` statements
|
- **Validation** after each dump: checks file size, header presence, counts `CREATE TABLE` statements
|
||||||
- Results cached in `settings.json` surviving container restarts
|
- Results cached in `settings.json` surviving container restarts
|
||||||
- Scheduled nightly at 02:30
|
- Scheduled nightly at 02:30
|
||||||
|
- Also triggered per-app by cross-drive backup before each run (`DumpStackDB`)
|
||||||
|
|
||||||
#### Layer 2: Restic Snapshots (`internal/backup/restic.go`)
|
#### Layer 2: Restic Snapshots (`internal/backup/restic.go`)
|
||||||
|
|
||||||
- Auto-generated repository password (32 random bytes, base64url)
|
- Auto-generated repository password (32 random bytes, base64url)
|
||||||
- Password synced to hub for disaster recovery
|
- Password synced to hub for disaster recovery
|
||||||
- Backs up: stacks directory + DB dump directory + enabled app HDD mount paths
|
- Backs up: stacks dir + DB dump dir + **ALL deployed apps' HDD mount paths** (mandatory, no opt-in)
|
||||||
|
- `resolveAppBackupPaths()` iterates all deployed stacks via `ListDeployedStacks()` — no `Enabled` flag
|
||||||
- Auto-detects and unlocks stale locks
|
- Auto-detects and unlocks stale locks
|
||||||
- Weekly prune on Sundays with configurable retention (keep-daily, keep-weekly, keep-monthly)
|
- Weekly prune on Sundays with configurable retention (keep-daily, keep-weekly, keep-monthly)
|
||||||
- Weekly integrity check (`restic check`) on Sunday 04:00
|
- Weekly integrity check (`restic check`) on Sunday 04:00
|
||||||
@@ -192,32 +197,39 @@ Implements the 3-2-1 backup rule by copying data to a different physical drive.
|
|||||||
- **rsync** — Simple mirror with `--delete` (fast, no versioning)
|
- **rsync** — Simple mirror with `--delete` (fast, no versioning)
|
||||||
- **restic** — Versioned, deduplicated, encrypted (shared repo across apps)
|
- **restic** — Versioned, deduplicated, encrypted (shared repo across apps)
|
||||||
- Per-app configuration: destination path, method, schedule (daily/weekly/manual)
|
- Per-app configuration: destination path, method, schedule (daily/weekly/manual)
|
||||||
|
- **Pre-backup DB dump**: `DumpStackDB()` runs before cross-drive backup to ensure DB consistency; non-fatal on failure
|
||||||
- **Drive-type-aware validation** (`ValidateDestination` / `CheckBackupDestination`):
|
- **Drive-type-aware validation** (`ValidateDestination` / `CheckBackupDestination`):
|
||||||
- External mount: block if <100 MB free; warn/block at 90%/95% usage
|
- External mount: block if <100 MB free; warn/block at 90%/95% usage
|
||||||
- System drive (same block device as `/`): require ≥10 GB free AND <90% usage to protect OS stability; allowed with a logged warning (no hard block for non-mount-point destinations)
|
- System drive (same block device as `/`): require ≥10 GB free AND <90% usage; allowed with logged warning
|
||||||
- Web UI `CheckBackupDestination` matches runner thresholds — no surprise divergence between UI and actual enforcement
|
|
||||||
- **Rsync destination layout** (`runRsyncBackup`):
|
- **Rsync destination layout** (`runRsyncBackup`):
|
||||||
- Single mount: data goes directly into `backups/rsync/<app>/` (no extra nesting)
|
- Single mount: data goes directly into `backups/rsync/<app>/` (no extra nesting)
|
||||||
- Multiple mounts: each gets a `backups/rsync/<app>/<leaf>/` subfolder named after the mount's base directory; duplicate leaf names disambiguated with `_N` suffix
|
- Multiple mounts: each gets `backups/rsync/<app>/<leaf>/` subfolder; duplicate leaf names get `_N` suffix
|
||||||
- DB dump files excluded: `--exclude backups/*.sql.gz`, `--exclude backups/*.sql`, `--exclude backups/*.dump` — avoids duplicating data already managed by the pg_dump layer
|
- DB dump files excluded: `--exclude backups/*.sql.gz/sql/dump` — avoids duplicating pg_dump data
|
||||||
- Safety guards: destination ≠ source, path-overlap check, writable check
|
- Safety guards: destination ≠ source, path-overlap check, writable check
|
||||||
- **Chained execution**: cross-drive runs immediately after nightly restic backup (daily apps every night, weekly apps on Sundays) for DB/file consistency
|
- **Chained execution**: cross-drive runs immediately after nightly restic backup (daily apps every night, weekly apps on Sundays)
|
||||||
- Per-app concurrency lock prevents overlapping runs
|
- Per-app concurrency lock prevents overlapping runs
|
||||||
- Status tracking (last_run, duration, size, error) persisted to settings.json
|
- Status tracking (last_run, duration, size, error) persisted to settings.json
|
||||||
|
|
||||||
#### Restore (`internal/backup/restore.go`)
|
#### Restore (`internal/backup/restore.go`)
|
||||||
|
|
||||||
- Per-app restore from restic snapshots
|
All deployed apps appear in the restore dropdown — not just those with HDD data.
|
||||||
- Snapshot filtering by app: `GET /api/backup/snapshots?stack={name}` returns only snapshots whose paths overlap the app's HDD mounts
|
|
||||||
- **Auto stop/restart**: stops the app's containers before `restic restore`, restarts after (even on failure)
|
| App type | DB restored | Config restored | User data restored |
|
||||||
- Human-friendly snapshot display: `2026-02-17 hetfo 03:00 (a3f2b1)`
|
|----------|------------|-----------------|-------------------|
|
||||||
|
| Has HDD data | ✓ | ✓ | ✓ (always — mandatory) |
|
||||||
|
| DB only, no HDD | ✓ | ✓ | n/a |
|
||||||
|
| No DB, no HDD | — | ✓ | n/a |
|
||||||
|
|
||||||
|
- Restore type info shown in UI when app selected (Hungarian banner: full / config+DB / config only)
|
||||||
|
- Snapshot API: apps without HDD mounts return all snapshots (all contain stacks dir + DB dumps)
|
||||||
|
- **Auto stop/restart**: stops app before `restic restore`, restarts after (even on failure)
|
||||||
- Running flag prevents concurrent backup/restore operations
|
- Running flag prevents concurrent backup/restore operations
|
||||||
|
|
||||||
#### Backup Page UI
|
#### Backup Page UI
|
||||||
|
|
||||||
The backups page shows a unified per-app status table:
|
The backups page shows a unified per-app status table:
|
||||||
- **Status dot**: green (fully covered), yellow (warning — failed run, system drive, disk full), red (HDD data without cross-drive), auto (no user data)
|
- **Status dot**: green (fully covered), yellow (warning — failed run, system drive, disk full), red (HDD data without cross-drive), auto (no user data)
|
||||||
- Expandable row per app showing all 3 backup layers (DB, Docker volumes, user data)
|
- Expandable row per app showing all 3 backup layers (DB, Konfiguráció, user data)
|
||||||
- Schedule overview with next run times
|
- Schedule overview with next run times
|
||||||
- Snapshot history table (last 20 snapshots with ID, time, data added)
|
- Snapshot history table (last 20 snapshots with ID, time, data added)
|
||||||
- Repository info card (path, size, snapshot count, encryption key with show/copy)
|
- Repository info card (path, size, snapshot count, encryption key with show/copy)
|
||||||
|
|||||||
@@ -134,6 +134,11 @@ func main() {
|
|||||||
// --- Initialize cross-drive backup runner ---
|
// --- Initialize cross-drive backup runner ---
|
||||||
crossDriveRunner := backup.NewCrossDriveRunner(sett, stackProv, logger)
|
crossDriveRunner := backup.NewCrossDriveRunner(sett, stackProv, logger)
|
||||||
|
|
||||||
|
// Wire cross-drive → backup manager for pre-backup DB dumps
|
||||||
|
if backupMgr != nil {
|
||||||
|
crossDriveRunner.SetDBDumper(backupMgr)
|
||||||
|
}
|
||||||
|
|
||||||
// --- Initialize alert manager ---
|
// --- Initialize alert manager ---
|
||||||
alertMgr := web.NewAlertManager(logger)
|
alertMgr := web.NewAlertManager(logger)
|
||||||
|
|
||||||
|
|||||||
@@ -461,8 +461,11 @@ func (r *Router) backupSnapshots(w http.ResponseWriter, req *http.Request) {
|
|||||||
if stackName := req.URL.Query().Get("stack"); stackName != "" {
|
if stackName := req.URL.Query().Get("stack"); stackName != "" {
|
||||||
mounts := r.backupMgr.GetStackHDDMounts(stackName)
|
mounts := r.backupMgr.GetStackHDDMounts(stackName)
|
||||||
if len(mounts) > 0 {
|
if len(mounts) > 0 {
|
||||||
|
// App has HDD data — filter to snapshots containing those paths
|
||||||
snapshots = filterSnapshotsByPaths(snapshots, mounts)
|
snapshots = filterSnapshotsByPaths(snapshots, mounts)
|
||||||
}
|
}
|
||||||
|
// Apps without HDD mounts: return all snapshots (they all contain
|
||||||
|
// the stacks dir + DB dumps which cover this app's config and database)
|
||||||
}
|
}
|
||||||
|
|
||||||
if snapshots == nil {
|
if snapshots == nil {
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ type AppDockerVolume struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DiscoverAppData discovers backup-relevant data for all deployed apps.
|
// DiscoverAppData discovers backup-relevant data for all deployed apps.
|
||||||
func DiscoverAppData(provider StackDataProvider, backupPrefs map[string]bool, discoveredDBs []DiscoveredDB) []AppBackupInfo {
|
// All apps with HDD data are backed up automatically (mandatory — no opt-in).
|
||||||
|
func DiscoverAppData(provider StackDataProvider, discoveredDBs []DiscoveredDB) []AppBackupInfo {
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -97,7 +98,8 @@ func DiscoverAppData(provider StackDataProvider, backupPrefs map[string]bool, di
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info.BackupEnabled = backupPrefs[stack.Name]
|
// All apps with HDD data are backed up automatically (mandatory)
|
||||||
|
info.BackupEnabled = info.HasHDDData
|
||||||
|
|
||||||
result = append(result, info)
|
result = append(result, info)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -425,24 +425,18 @@ func (m *Manager) GetStackHDDMounts(name string) []string {
|
|||||||
return m.stackProvider.GetStackHDDMounts(name)
|
return m.stackProvider.GetStackHDDMounts(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveAppBackupPaths returns HDD paths for all enabled app backups.
|
// resolveAppBackupPaths returns HDD paths for ALL deployed apps.
|
||||||
|
// User data backup is mandatory — every app with HDD mounts is included.
|
||||||
func (m *Manager) resolveAppBackupPaths() []string {
|
func (m *Manager) resolveAppBackupPaths() []string {
|
||||||
if m.stackProvider == nil || m.settings == nil {
|
if m.stackProvider == nil {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
appBackupMap := m.settings.GetAppBackupMap()
|
|
||||||
if len(appBackupMap) == 0 {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var paths []string
|
var paths []string
|
||||||
seen := make(map[string]bool)
|
seen := make(map[string]bool)
|
||||||
|
|
||||||
for stackName, enabled := range appBackupMap {
|
for _, stack := range m.stackProvider.ListDeployedStacks() {
|
||||||
if !enabled {
|
hddMounts := m.stackProvider.GetStackHDDMounts(stack.Name)
|
||||||
continue
|
|
||||||
}
|
|
||||||
hddMounts := m.stackProvider.GetStackHDDMounts(stackName)
|
|
||||||
for _, mount := range hddMounts {
|
for _, mount := range hddMounts {
|
||||||
if seen[mount] {
|
if seen[mount] {
|
||||||
continue
|
continue
|
||||||
@@ -450,13 +444,58 @@ func (m *Manager) resolveAppBackupPaths() []string {
|
|||||||
if _, err := os.Stat(mount); err == nil {
|
if _, err := os.Stat(mount); err == nil {
|
||||||
paths = append(paths, mount)
|
paths = append(paths, mount)
|
||||||
seen[mount] = true
|
seen[mount] = true
|
||||||
m.logger.Printf("[DEBUG] Including app data: %s (from %s)", mount, stackName)
|
m.logger.Printf("[DEBUG] Including app data: %s (from %s)", mount, stack.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DumpStackDB runs a database dump for containers belonging to a specific stack.
|
||||||
|
// Used by cross-drive backup to ensure DB state matches user data.
|
||||||
|
func (m *Manager) DumpStackDB(ctx context.Context, stackName string) error {
|
||||||
|
dbs, err := DiscoverDatabases(ctx, m.logger)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("database discovery failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var stackDBs []DiscoveredDB
|
||||||
|
for _, db := range dbs {
|
||||||
|
if db.StackName == stackName {
|
||||||
|
stackDBs = append(stackDBs, db)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(stackDBs) == 0 {
|
||||||
|
m.logger.Printf("[DEBUG] No databases found for stack %s — skipping pre-backup dump", stackName)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
m.logger.Printf("[INFO] Running pre-backup DB dump for %s (%d database(s))", stackName, len(stackDBs))
|
||||||
|
results := DumpAll(ctx, stackDBs, m.cfg.Paths.DBDumpDir, m.logger)
|
||||||
|
|
||||||
|
for _, r := range results {
|
||||||
|
if r.Error != nil {
|
||||||
|
return fmt.Errorf("DB dump failed for %s: %w", r.DB.ContainerName, r.Error)
|
||||||
|
}
|
||||||
|
m.logger.Printf("[INFO] Pre-backup DB dump OK: %s (%s)", r.DB.ContainerName, humanizeBytes(r.Size))
|
||||||
|
|
||||||
|
// Persist validation to settings
|
||||||
|
if m.settings != nil && r.FilePath != "" {
|
||||||
|
filename := filepath.Base(r.FilePath)
|
||||||
|
cache := settings.DBValidationCache{
|
||||||
|
ValidatedAt: time.Now().Format(time.RFC3339),
|
||||||
|
TableCount: r.Validation.TableCount,
|
||||||
|
HasHeader: r.Validation.Valid,
|
||||||
|
}
|
||||||
|
if !r.Validation.Valid {
|
||||||
|
cache.Error = r.Validation.Error
|
||||||
|
}
|
||||||
|
_ = m.settings.SetDBValidation(filename, cache)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func shouldPrune(schedule string) bool {
|
func shouldPrune(schedule string) bool {
|
||||||
loc, err := time.LoadLocation("Europe/Budapest")
|
loc, err := time.LoadLocation("Europe/Budapest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -542,10 +581,9 @@ func (m *Manager) RefreshCache(nextDBDump, nextBackup time.Time) {
|
|||||||
status.DiscoveredDBs = dbs
|
status.DiscoveredDBs = dbs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discover app data (for per-app backup toggles)
|
// Discover app data — all deployed stacks, backup is mandatory
|
||||||
if m.stackProvider != nil {
|
if m.stackProvider != nil {
|
||||||
backupPrefs := m.settings.GetAppBackupMap()
|
status.AppDataInfo = DiscoverAppData(m.stackProvider, status.DiscoveredDBs)
|
||||||
status.AppDataInfo = DiscoverAppData(m.stackProvider, backupPrefs, status.DiscoveredDBs)
|
|
||||||
|
|
||||||
// Include enabled app backup paths in the displayed BackupPaths
|
// Include enabled app backup paths in the displayed BackupPaths
|
||||||
appPaths := m.resolveAppBackupPaths()
|
appPaths := m.resolveAppBackupPaths()
|
||||||
|
|||||||
@@ -15,10 +15,16 @@ import (
|
|||||||
"gitea.dooplex.hu/admin/felhom-controller/internal/system"
|
"gitea.dooplex.hu/admin/felhom-controller/internal/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DBDumper can run a database dump for a specific stack.
|
||||||
|
type DBDumper interface {
|
||||||
|
DumpStackDB(ctx context.Context, stackName string) error
|
||||||
|
}
|
||||||
|
|
||||||
// CrossDriveRunner handles per-app backup to secondary storage.
|
// CrossDriveRunner handles per-app backup to secondary storage.
|
||||||
type CrossDriveRunner struct {
|
type CrossDriveRunner struct {
|
||||||
sett *settings.Settings
|
sett *settings.Settings
|
||||||
stackProvider StackDataProvider
|
stackProvider StackDataProvider
|
||||||
|
dbDumper DBDumper
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
running map[string]bool // per-app running state
|
running map[string]bool // per-app running state
|
||||||
@@ -34,6 +40,12 @@ func NewCrossDriveRunner(sett *settings.Settings, provider StackDataProvider, lo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetDBDumper sets the DB dumper for pre-backup database dumps.
|
||||||
|
// Called after backup manager is initialized (avoids circular init dependency).
|
||||||
|
func (r *CrossDriveRunner) SetDBDumper(d DBDumper) {
|
||||||
|
r.dbDumper = d
|
||||||
|
}
|
||||||
|
|
||||||
// RunAppBackup runs cross-drive backup for a single app.
|
// RunAppBackup runs cross-drive backup for a single app.
|
||||||
func (r *CrossDriveRunner) RunAppBackup(ctx context.Context, stackName string) error {
|
func (r *CrossDriveRunner) RunAppBackup(ctx context.Context, stackName string) error {
|
||||||
cfg := r.sett.GetCrossDriveConfig(stackName)
|
cfg := r.sett.GetCrossDriveConfig(stackName)
|
||||||
@@ -64,6 +76,14 @@ func (r *CrossDriveRunner) RunAppBackup(ctx context.Context, stackName string) e
|
|||||||
r.logger.Printf("[INFO] Cross-drive backup starting: %s → %s (method: %s)",
|
r.logger.Printf("[INFO] Cross-drive backup starting: %s → %s (method: %s)",
|
||||||
stackName, cfg.DestinationPath, cfg.Method)
|
stackName, cfg.DestinationPath, cfg.Method)
|
||||||
|
|
||||||
|
// Trigger fresh DB dump for this app before cross-drive backup
|
||||||
|
if r.dbDumper != nil {
|
||||||
|
if err := r.dbDumper.DumpStackDB(ctx, stackName); err != nil {
|
||||||
|
r.logger.Printf("[WARN] Pre-backup DB dump failed for %s: %v — proceeding with user data backup", stackName, err)
|
||||||
|
// Non-fatal: user data backup is still valuable without fresh dump
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := r.ValidateDestination(cfg.DestinationPath); err != nil {
|
if err := r.ValidateDestination(cfg.DestinationPath); err != nil {
|
||||||
r.updateStatus(stackName, "error", err.Error(), time.Since(start), "")
|
r.updateStatus(stackName, "error", err.Error(), time.Since(start), "")
|
||||||
return fmt.Errorf("destination validation failed: %w", err)
|
return fmt.Errorf("destination validation failed: %w", err)
|
||||||
|
|||||||
@@ -2,35 +2,26 @@ package backup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// snapshotIDRe validates restic snapshot IDs: 8-64 lowercase hex characters.
|
// snapshotIDRe validates restic snapshot IDs: 8-64 lowercase hex characters.
|
||||||
var snapshotIDRe = regexp.MustCompile(`^[0-9a-f]{8,64}$`)
|
var snapshotIDRe = regexp.MustCompile(`^[0-9a-f]{8,64}$`)
|
||||||
|
|
||||||
// RestoreApp restores an app's HDD data from a restic snapshot.
|
// RestoreApp restores an app from a restic snapshot.
|
||||||
|
// All apps get config + DB dump restored. Apps with HDD data also get user data restored.
|
||||||
func (m *Manager) RestoreApp(stackName, snapshotID string) error {
|
func (m *Manager) RestoreApp(stackName, snapshotID string) error {
|
||||||
// Validate app has backup enabled
|
|
||||||
if !m.settings.IsAppBackupEnabled(stackName) {
|
|
||||||
return fmt.Errorf("backup not enabled for %s", stackName)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve HDD paths for this app
|
|
||||||
if m.stackProvider == nil {
|
if m.stackProvider == nil {
|
||||||
return fmt.Errorf("stack provider not configured")
|
return fmt.Errorf("stack provider not configured")
|
||||||
}
|
}
|
||||||
hddMounts := m.stackProvider.GetStackHDDMounts(stackName)
|
|
||||||
if len(hddMounts) == 0 {
|
|
||||||
return fmt.Errorf("no HDD data paths found for %s", stackName)
|
|
||||||
}
|
|
||||||
|
|
||||||
// H4: Validate snapshot ID format by regex instead of listing all snapshots (list caps at 100).
|
// Validate snapshot ID format
|
||||||
// restic restore will return a clear error if the snapshot ID doesn't exist.
|
|
||||||
if !snapshotIDRe.MatchString(snapshotID) {
|
if !snapshotIDRe.MatchString(snapshotID) {
|
||||||
return fmt.Errorf("invalid snapshot ID: must be 8-64 lowercase hex characters")
|
return fmt.Errorf("invalid snapshot ID: must be 8-64 lowercase hex characters")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the running flag to prevent concurrent backup/restore
|
// Prevent concurrent operations
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
if m.running {
|
if m.running {
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
@@ -38,35 +29,66 @@ func (m *Manager) RestoreApp(stackName, snapshotID string) error {
|
|||||||
}
|
}
|
||||||
m.running = true
|
m.running = true
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
m.running = false
|
m.running = false
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
m.logger.Printf("[WARN] RESTORE starting: stack=%s, snapshot=%s, paths=%v", stackName, snapshotID, hddMounts)
|
// Determine what to restore
|
||||||
|
hddMounts := m.stackProvider.GetStackHDDMounts(stackName)
|
||||||
|
hasHDD := len(hddMounts) > 0
|
||||||
|
|
||||||
// Stop the app before restore to avoid data corruption
|
// Build list of paths to restore from the snapshot
|
||||||
if err := m.stackProvider.StopStack(stackName); err != nil {
|
var restorePaths []string
|
||||||
m.logger.Printf("[WARN] RESTORE could not stop %s before restore: %v (proceeding anyway)", stackName, err)
|
|
||||||
|
// Always restore the stack's config dir (compose + app.yaml + .felhom.yml)
|
||||||
|
composePath, ok := m.stackProvider.GetStackComposePath(stackName)
|
||||||
|
if ok {
|
||||||
|
stackDir := filepath.Dir(composePath)
|
||||||
|
restorePaths = append(restorePaths, stackDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute restore
|
// Restore DB dump files for this stack
|
||||||
if err := m.restic.RestoreAppData(snapshotID, hddMounts); err != nil {
|
if m.cfg.Paths.DBDumpDir != "" {
|
||||||
|
restorePaths = append(restorePaths, m.cfg.Paths.DBDumpDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore HDD data (always included for apps that have it — backup is mandatory)
|
||||||
|
if hasHDD {
|
||||||
|
restorePaths = append(restorePaths, hddMounts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(restorePaths) == 0 {
|
||||||
|
return fmt.Errorf("no restorable paths found for %s", stackName)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.logger.Printf("[WARN] RESTORE starting: stack=%s, snapshot=%s, paths=%v, hasHDD=%v",
|
||||||
|
stackName, snapshotID, restorePaths, hasHDD)
|
||||||
|
|
||||||
|
// Stop the app before restore
|
||||||
|
if err := m.stackProvider.StopStack(stackName); err != nil {
|
||||||
|
m.logger.Printf("[WARN] RESTORE could not stop %s: %v (proceeding anyway)", stackName, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute restore via restic
|
||||||
|
if err := m.restic.RestoreAppData(snapshotID, restorePaths); err != nil {
|
||||||
m.logger.Printf("[ERROR] RESTORE failed for %s: %v", stackName, err)
|
m.logger.Printf("[ERROR] RESTORE failed for %s: %v", stackName, err)
|
||||||
// Try to restart the app even on failure
|
|
||||||
if startErr := m.stackProvider.StartStack(stackName); startErr != nil {
|
if startErr := m.stackProvider.StartStack(stackName); startErr != nil {
|
||||||
m.logger.Printf("[WARN] RESTORE could not restart %s after failed restore: %v", stackName, startErr)
|
m.logger.Printf("[WARN] RESTORE could not restart %s after failure: %v", stackName, startErr)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart the app after successful restore
|
// Restart the app
|
||||||
if err := m.stackProvider.StartStack(stackName); err != nil {
|
if err := m.stackProvider.StartStack(stackName); err != nil {
|
||||||
m.logger.Printf("[WARN] RESTORE could not restart %s after restore: %v", stackName, err)
|
m.logger.Printf("[WARN] RESTORE could not restart %s after restore: %v", stackName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.logger.Printf("[INFO] RESTORE completed: stack=%s, snapshot=%s", stackName, snapshotID)
|
restoreType := "config+DB"
|
||||||
|
if hasHDD {
|
||||||
|
restoreType = "full (config+DB+userdata)"
|
||||||
|
}
|
||||||
|
m.logger.Printf("[INFO] RESTORE completed: stack=%s, snapshot=%s, type=%s", stackName, snapshotID, restoreType)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,71 +232,6 @@ func (s *Settings) SetNotificationPrefs(prefs *NotificationPrefs) error {
|
|||||||
return s.save()
|
return s.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAppBackupEnabled returns whether backup is enabled for the given stack.
|
|
||||||
func (s *Settings) IsAppBackupEnabled(stackName string) bool {
|
|
||||||
s.mu.RLock()
|
|
||||||
defer s.mu.RUnlock()
|
|
||||||
if s.AppBackup == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return s.AppBackup[stackName].Enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetAppBackup enables or disables backup for a stack and saves to disk.
|
|
||||||
// Preserves existing CrossDrive config.
|
|
||||||
func (s *Settings) SetAppBackup(stackName string, enabled bool) error {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
if s.AppBackup == nil {
|
|
||||||
s.AppBackup = make(map[string]AppBackupPrefs)
|
|
||||||
}
|
|
||||||
existing := s.AppBackup[stackName]
|
|
||||||
existing.Enabled = enabled
|
|
||||||
s.AppBackup[stackName] = existing
|
|
||||||
return s.save()
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAppBackupMap returns a map of stack_name -> enabled for all app backup prefs.
|
|
||||||
func (s *Settings) GetAppBackupMap() map[string]bool {
|
|
||||||
s.mu.RLock()
|
|
||||||
defer s.mu.RUnlock()
|
|
||||||
if s.AppBackup == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
result := make(map[string]bool, len(s.AppBackup))
|
|
||||||
for k, v := range s.AppBackup {
|
|
||||||
result[k] = v.Enabled
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetAppBackupBulk updates backup prefs for all stacks at once and saves to disk.
|
|
||||||
// Preserves existing CrossDrive configs and stacks not present in the input.
|
|
||||||
func (s *Settings) SetAppBackupBulk(prefs map[string]bool) error {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
if s.AppBackup == nil {
|
|
||||||
s.AppBackup = make(map[string]AppBackupPrefs)
|
|
||||||
}
|
|
||||||
for name, enabled := range prefs {
|
|
||||||
existing := s.AppBackup[name] // preserves CrossDrive
|
|
||||||
existing.Enabled = enabled
|
|
||||||
s.AppBackup[name] = existing
|
|
||||||
}
|
|
||||||
return s.save()
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAppBackupPrefs returns the full AppBackupPrefs for a stack.
|
|
||||||
func (s *Settings) GetAppBackupPrefs(stackName string) (AppBackupPrefs, bool) {
|
|
||||||
s.mu.RLock()
|
|
||||||
defer s.mu.RUnlock()
|
|
||||||
if s.AppBackup == nil {
|
|
||||||
return AppBackupPrefs{}, false
|
|
||||||
}
|
|
||||||
prefs, ok := s.AppBackup[stackName]
|
|
||||||
return prefs, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCrossDriveConfig returns the cross-drive backup config for a stack (nil if not set).
|
// GetCrossDriveConfig returns the cross-drive backup config for a stack (nil if not set).
|
||||||
func (s *Settings) GetCrossDriveConfig(stackName string) *CrossDriveBackup {
|
func (s *Settings) GetCrossDriveConfig(stackName string) *CrossDriveBackup {
|
||||||
s.mu.RLock()
|
s.mu.RLock()
|
||||||
|
|||||||
@@ -281,7 +281,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- Volume layer -->
|
<!-- Volume layer -->
|
||||||
<div class="backup-layer-row">
|
<div class="backup-layer-row">
|
||||||
<span class="layer-label">Docker kötetek</span>
|
<span class="layer-label">Konfiguráció</span>
|
||||||
<span class="layer-badge">Auto</span>
|
<span class="layer-badge">Auto</span>
|
||||||
{{if .VolumeLastRun}}
|
{{if .VolumeLastRun}}
|
||||||
<span class="layer-last">Utolsó: {{.VolumeLastRun}}
|
<span class="layer-last">Utolsó: {{.VolumeLastRun}}
|
||||||
@@ -450,9 +450,7 @@
|
|||||||
<select id="restore-app" class="restore-select" onchange="onRestoreAppChange()">
|
<select id="restore-app" class="restore-select" onchange="onRestoreAppChange()">
|
||||||
<option value="">— Válasszon —</option>
|
<option value="">— Válasszon —</option>
|
||||||
{{range .Backup.AppDataInfo}}
|
{{range .Backup.AppDataInfo}}
|
||||||
{{if and .HasHDDData .BackupEnabled}}
|
<option value="{{.StackName}}" data-has-hdd="{{.HasHDDData}}" data-has-db="{{.HasDBDump}}">{{.DisplayName}}</option>
|
||||||
<option value="{{.StackName}}">{{.DisplayName}}</option>
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -462,6 +460,8 @@
|
|||||||
<option value="">— Válasszon alkalmazást —</option>
|
<option value="">— Válasszon alkalmazást —</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="restore-type-info" class="restore-info" style="display:none;margin-bottom:0.5rem">
|
||||||
|
</div>
|
||||||
<div id="restore-no-snapshots" class="restore-warning" style="display:none;">
|
<div id="restore-no-snapshots" class="restore-warning" style="display:none;">
|
||||||
Még nincs mentés felhasználói adattal.
|
Még nincs mentés felhasználói adattal.
|
||||||
</div>
|
</div>
|
||||||
@@ -606,16 +606,35 @@ function onRestoreAppChange() {
|
|||||||
var appName = sel.value;
|
var appName = sel.value;
|
||||||
var snapSel = document.getElementById('restore-snapshot');
|
var snapSel = document.getElementById('restore-snapshot');
|
||||||
var noSnaps = document.getElementById('restore-no-snapshots');
|
var noSnaps = document.getElementById('restore-no-snapshots');
|
||||||
|
var typeInfo = document.getElementById('restore-type-info');
|
||||||
|
|
||||||
document.getElementById('restore-confirm-cb').checked = false;
|
document.getElementById('restore-confirm-cb').checked = false;
|
||||||
document.getElementById('restore-btn').disabled = true;
|
document.getElementById('restore-btn').disabled = true;
|
||||||
noSnaps.style.display = 'none';
|
noSnaps.style.display = 'none';
|
||||||
|
typeInfo.style.display = 'none';
|
||||||
|
|
||||||
if (!appName) {
|
if (!appName) {
|
||||||
snapSel.innerHTML = '<option value="">— Válasszon alkalmazást —</option>';
|
snapSel.innerHTML = '<option value="">— Válasszon alkalmazást —</option>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine restore type from data attributes
|
||||||
|
var opt = sel.options[sel.selectedIndex];
|
||||||
|
var hasHDD = opt.getAttribute('data-has-hdd') === 'true';
|
||||||
|
var hasDB = opt.getAttribute('data-has-db') === 'true';
|
||||||
|
|
||||||
|
if (hasHDD) {
|
||||||
|
typeInfo.innerHTML = '🔄 Teljes visszaállítás: adatbázis + konfiguráció + felhasználói adatok a kiválasztott pillanatképből.';
|
||||||
|
typeInfo.className = 'restore-info';
|
||||||
|
} else if (hasDB) {
|
||||||
|
typeInfo.innerHTML = 'ℹ Adatbázis és konfiguráció visszaállítása — az alkalmazásnak nincs külön felhasználói adata.';
|
||||||
|
typeInfo.className = 'restore-info restore-info-partial';
|
||||||
|
} else {
|
||||||
|
typeInfo.innerHTML = 'ℹ Csak konfiguráció visszaállítása (compose fájlok, beállítások).';
|
||||||
|
typeInfo.className = 'restore-info restore-info-partial';
|
||||||
|
}
|
||||||
|
typeInfo.style.display = 'block';
|
||||||
|
|
||||||
snapSel.innerHTML = '<option value="">— Betöltés... —</option>';
|
snapSel.innerHTML = '<option value="">— Betöltés... —</option>';
|
||||||
|
|
||||||
fetch('/api/backup/snapshots?stack=' + encodeURIComponent(appName))
|
fetch('/api/backup/snapshots?stack=' + encodeURIComponent(appName))
|
||||||
|
|||||||
@@ -1921,6 +1921,21 @@ a.stat-card:hover {
|
|||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --- Backup page: Restore type info banners --- */
|
||||||
|
.restore-info {
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
background: rgba(59, 130, 246, 0.1);
|
||||||
|
border: 1px solid rgba(59, 130, 246, 0.3);
|
||||||
|
color: #93c5fd;
|
||||||
|
}
|
||||||
|
.restore-info-partial {
|
||||||
|
background: rgba(251, 191, 36, 0.1);
|
||||||
|
border-color: rgba(251, 191, 36, 0.3);
|
||||||
|
color: #fcd34d;
|
||||||
|
}
|
||||||
|
|
||||||
/* --- Backup page: Restore section --- */
|
/* --- Backup page: Restore section --- */
|
||||||
.restore-section {
|
.restore-section {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
Reference in New Issue
Block a user