(a) Docs: reserve tools/ scripts/ resources/ as LibrePortal folder names (apps must not bind-mount to them); document resources/ as the home for nest-able data AND for .sh payloads that execute on load (vs scripts/ for sourced functions); document the backup model (what's captured vs reproducible). (b) System-config backup so a bare-metal restore is self-sufficient — this is why the system root is its own tree. New scripts/backup/system/backup_system.sh: - backupSystemConfig snapshots <system>/configs (global settings, WebUI creds, and the BACKUP-LOCATION creds — otherwise the keys to reach your own backups live only on the box) to every enabled location. Lightweight static-dir snapshot — it does NOT go through backupAppStart (no containers to quiesce / DBs to dump). - restic adapter resticBackupSystemToLocation (tag system=config) + dispatcher engineBackupSystem; restore via resticRestoreSystemLatest / engineRestoreSystemLatest + backupRestoreSystemConfig (restores to a STAGING dir — never auto-overwrites live config). - backupAllApps runs it after the app loop. WebUI exclusion: backupAllApps skips the 'libreportal' app — its frontend + generated JSON regenerate, and its only state (the login) is in the system config now captured above. Nothing in its data dir warrants a snapshot. Verified with stubs: app loop skips libreportal + invokes the system backup; the system backup dispatches to both locations; backup/restore function names pair with the dispatcher. NOTE: restic-only (the sole live engine adapter); end-to-end repo round-trip still needs a live box before being relied on. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> Signed-off-by: librelad <librelad@digitalangels.vip>
75 lines
2.7 KiB
Bash
75 lines
2.7 KiB
Bash
#!/bin/bash
|
|
|
|
# System-config backup.
|
|
#
|
|
# Snapshots the system config tree (<system>/configs — global settings, WebUI
|
|
# credentials, and crucially the BACKUP-LOCATION credentials) to every enabled
|
|
# backup location, so a bare-metal restore is self-sufficient. Without this the
|
|
# location creds live only on the box: lose it and you can't even reach your own
|
|
# remote backups (chicken-and-egg). It is a lightweight, static-dir snapshot — no
|
|
# container quiescing or DB dumps (those are per-app concerns), so it does NOT go
|
|
# through backupAppStart. The install tree (code) is reproducible from the release
|
|
# and is deliberately NOT included; per-app data is handled by backupAppStart.
|
|
|
|
backupSystemConfig()
|
|
{
|
|
local source_path="${configs_dir%/}"
|
|
if [[ ! -d "$source_path" ]]; then
|
|
isNotice "System config dir not found ($source_path) — skipping system backup"
|
|
return 0
|
|
fi
|
|
if [[ -z "$(resticEnabledLocations)" ]]; then
|
|
isNotice "No backup locations enabled — skipping system config backup"
|
|
return 0
|
|
fi
|
|
|
|
isHeader "Backing up system config"
|
|
engineEnsureAllLocationsReady
|
|
|
|
local idx ok=0 fail=0
|
|
while IFS= read -r idx; do
|
|
[[ -z "$idx" ]] && continue
|
|
if engineBackupSystem "$idx" >/dev/null; then
|
|
ok=$((ok + 1))
|
|
else
|
|
fail=$((fail + 1))
|
|
fi
|
|
done < <(resticEnabledLocations)
|
|
|
|
if [[ $ok -eq 0 ]]; then
|
|
isError "System config backup failed on all locations"
|
|
return 1
|
|
fi
|
|
if [[ $fail -gt 0 ]]; then
|
|
isNotice "System config backed up to $ok location(s), failed on $fail"
|
|
else
|
|
isSuccessful "System config backed up to $ok location(s)"
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
# Restore the latest system-config snapshot from a location into a STAGING dir.
|
|
# Deliberately does NOT overwrite live config — recovering creds/settings is a
|
|
# review-then-copy step, never an automatic blast over a running control plane.
|
|
backupRestoreSystemConfig()
|
|
{
|
|
local idx="${1:-}"
|
|
[[ -z "$idx" ]] && idx=$(resticEnabledLocations | head -1)
|
|
if [[ -z "$idx" ]]; then
|
|
isError "No enabled backup location to restore the system config from"
|
|
return 1
|
|
fi
|
|
|
|
local staging="${restore_dir%/}/system-config"
|
|
runFileOp mkdir -p "$staging"
|
|
|
|
isHeader "Restoring system config (to staging — live config is untouched)"
|
|
if engineRestoreSystemLatest "$idx" "$staging"; then
|
|
isSuccessful "System config restored to: $staging"
|
|
isNotice "Review it, then copy what you need into ${configs_dir} (backup-location creds, logins, settings). Live config was NOT overwritten."
|
|
return 0
|
|
fi
|
|
isError "System config restore failed"
|
|
return 1
|
|
}
|