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:
@@ -2,35 +2,26 @@ package backup
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// snapshotIDRe validates restic snapshot IDs: 8-64 lowercase hex characters.
|
||||
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 {
|
||||
// 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 {
|
||||
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).
|
||||
// restic restore will return a clear error if the snapshot ID doesn't exist.
|
||||
// Validate snapshot ID format
|
||||
if !snapshotIDRe.MatchString(snapshotID) {
|
||||
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()
|
||||
if m.running {
|
||||
m.mu.Unlock()
|
||||
@@ -38,35 +29,66 @@ func (m *Manager) RestoreApp(stackName, snapshotID string) error {
|
||||
}
|
||||
m.running = true
|
||||
m.mu.Unlock()
|
||||
|
||||
defer func() {
|
||||
m.mu.Lock()
|
||||
m.running = false
|
||||
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
|
||||
if err := m.stackProvider.StopStack(stackName); err != nil {
|
||||
m.logger.Printf("[WARN] RESTORE could not stop %s before restore: %v (proceeding anyway)", stackName, err)
|
||||
// Build list of paths to restore from the snapshot
|
||||
var restorePaths []string
|
||||
|
||||
// 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
|
||||
if err := m.restic.RestoreAppData(snapshotID, hddMounts); err != nil {
|
||||
// Restore DB dump files for this stack
|
||||
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)
|
||||
// Try to restart the app even on failure
|
||||
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
|
||||
}
|
||||
|
||||
// Restart the app after successful restore
|
||||
// Restart the app
|
||||
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("[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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user