(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>
70 lines
1.9 KiB
Bash
70 lines
1.9 KiB
Bash
#!/bin/bash
|
|
|
|
resticRestoreSnapshot()
|
|
{
|
|
local idx="$1"
|
|
local snapshot_id="$2"
|
|
local target_dir="$3"
|
|
local include_path="$4"
|
|
|
|
if [[ -z "$snapshot_id" || -z "$target_dir" ]]; then
|
|
isError "resticRestoreSnapshot requires snapshot_id and target_dir"
|
|
return 1
|
|
fi
|
|
|
|
resticEnvExport "$idx" || return 1
|
|
|
|
runFileOp mkdir -p "$target_dir"
|
|
|
|
local args=(restore "$snapshot_id" --target "$target_dir")
|
|
[[ -n "$include_path" ]] && args+=(--include "$include_path")
|
|
|
|
isNotice "Restoring ${snapshot_id:0:8} from $(resticLocationName "$idx") → $target_dir"
|
|
runBackupOp restic "${args[@]}"
|
|
local rc=$?
|
|
resticEnvUnset
|
|
return $rc
|
|
}
|
|
|
|
resticRestoreAppLatest()
|
|
{
|
|
local idx="$1"
|
|
local app_name="$2"
|
|
local target_dir="$3"
|
|
local host="${4:-$CFG_INSTALL_NAME}"
|
|
|
|
local snapshot_id
|
|
snapshot_id=$(resticSnapshotLatestId "$idx" "$app_name" "$host")
|
|
|
|
if [[ -z "$snapshot_id" ]]; then
|
|
isError "No snapshot found in $(resticLocationName "$idx") for app=$app_name host=$host"
|
|
return 1
|
|
fi
|
|
|
|
local include_path="$containers_dir$app_name"
|
|
resticRestoreSnapshot "$idx" "$snapshot_id" "$target_dir" "$include_path"
|
|
}
|
|
|
|
resticRestoreSystemLatest()
|
|
{
|
|
local idx="$1"
|
|
local target_dir="$2"
|
|
local host="${3:-$CFG_INSTALL_NAME}"
|
|
|
|
resticEnvExport "$idx" || return 1
|
|
local snapshot_id
|
|
snapshot_id=$(runBackupOp restic snapshots \
|
|
--tag "system=config" --host "$host" \
|
|
--latest 1 --json --no-lock 2>/dev/null | \
|
|
grep -o '"short_id":"[^"]*"' | head -1 | cut -d'"' -f4)
|
|
resticEnvUnset
|
|
|
|
if [[ -z "$snapshot_id" ]]; then
|
|
isError "No system-config snapshot found in $(resticLocationName "$idx") for host=$host"
|
|
return 1
|
|
fi
|
|
|
|
# Whole-snapshot restore (the snapshot is just the config tree) into staging.
|
|
resticRestoreSnapshot "$idx" "$snapshot_id" "$target_dir"
|
|
}
|