(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>
133 lines
3.6 KiB
Bash
133 lines
3.6 KiB
Bash
#!/bin/bash
|
|
|
|
resticBackupAppToLocation()
|
|
{
|
|
local idx="$1"
|
|
local app_name="$2"
|
|
local manifest_sha="$3"
|
|
local source_path="$containers_dir$app_name"
|
|
|
|
if [[ ! -d "$source_path" ]]; then
|
|
isError "Source path missing for $app_name: $source_path"
|
|
return 1
|
|
fi
|
|
|
|
resticEnvExport "$idx" || return 1
|
|
|
|
local host_tag="${CFG_INSTALL_NAME:-libreportal}"
|
|
local extra_tags=(
|
|
--tag "app=$app_name"
|
|
--tag "host=$host_tag"
|
|
--tag "engine=libreportal"
|
|
)
|
|
[[ -n "$manifest_sha" ]] && extra_tags+=(--tag "manifest=$manifest_sha")
|
|
|
|
# On the live path backup_app_start sets $backup_exclude_paths to the raw
|
|
# DB data dirs the dumps replace; keep them out of the snapshot.
|
|
local exclude_args=()
|
|
local p
|
|
while IFS= read -r p; do
|
|
[[ -n "$p" ]] && exclude_args+=(--exclude "$p")
|
|
done <<< "${backup_exclude_paths:-}"
|
|
|
|
local loc_name
|
|
loc_name=$(resticLocationName "$idx")
|
|
# Logs go to stderr so this function's stdout is ONLY the snapshot id —
|
|
# the caller captures it with $() and feeds it to verify/retention.
|
|
isNotice "Snapshotting $app_name → $loc_name" >&2
|
|
local output
|
|
output=$(runBackupOp restic backup \
|
|
--host "$host_tag" \
|
|
"${extra_tags[@]}" \
|
|
"${exclude_args[@]}" \
|
|
--exclude-caches \
|
|
--json \
|
|
"$source_path" 2>&1)
|
|
local rc=$?
|
|
|
|
local snapshot_id
|
|
snapshot_id=$(echo "$output" | grep -o '"snapshot_id":"[^"]*"' | tail -1 | cut -d'"' -f4)
|
|
|
|
if [[ $rc -eq 0 ]]; then
|
|
isSuccessful "Backup created in $loc_name: ${snapshot_id:0:8}" >&2
|
|
echo "$snapshot_id"
|
|
else
|
|
isError "Backup to $loc_name failed for $app_name" >&2
|
|
echo "$output" | tail -10 >&2
|
|
fi
|
|
|
|
resticEnvUnset
|
|
return $rc
|
|
}
|
|
|
|
resticBackupSystemToLocation()
|
|
{
|
|
local idx="$1"
|
|
local source_path="${configs_dir%/}"
|
|
|
|
if [[ ! -d "$source_path" ]]; then
|
|
isError "System config path missing: $source_path"
|
|
return 1
|
|
fi
|
|
|
|
resticEnvExport "$idx" || return 1
|
|
|
|
local host_tag="${CFG_INSTALL_NAME:-libreportal}"
|
|
local loc_name
|
|
loc_name=$(resticLocationName "$idx")
|
|
isNotice "Snapshotting system config → $loc_name" >&2
|
|
local output
|
|
output=$(runBackupOp restic backup \
|
|
--host "$host_tag" \
|
|
--tag "system=config" \
|
|
--tag "host=$host_tag" \
|
|
--tag "engine=libreportal" \
|
|
--exclude-caches \
|
|
--json \
|
|
"$source_path" 2>&1)
|
|
local rc=$?
|
|
|
|
local snapshot_id
|
|
snapshot_id=$(echo "$output" | grep -o '"snapshot_id":"[^"]*"' | tail -1 | cut -d'"' -f4)
|
|
|
|
if [[ $rc -eq 0 ]]; then
|
|
isSuccessful "System config backed up to $loc_name: ${snapshot_id:0:8}" >&2
|
|
echo "$snapshot_id"
|
|
else
|
|
isError "System config backup to $loc_name failed" >&2
|
|
echo "$output" | tail -10 >&2
|
|
fi
|
|
|
|
resticEnvUnset
|
|
return $rc
|
|
}
|
|
|
|
resticBackupAppAllLocations()
|
|
{
|
|
local app_name="$1"
|
|
local manifest_sha="$2"
|
|
local failed=0
|
|
local succeeded=0
|
|
local idx
|
|
|
|
while IFS= read -r idx; do
|
|
[[ -z "$idx" ]] && continue
|
|
if resticBackupAppToLocation "$idx" "$app_name" "$manifest_sha" >/dev/null; then
|
|
succeeded=$((succeeded + 1))
|
|
else
|
|
failed=$((failed + 1))
|
|
fi
|
|
done < <(resticEnabledLocations)
|
|
|
|
if [[ $succeeded -eq 0 ]]; then
|
|
isError "All backup targets failed for $app_name"
|
|
return 1
|
|
fi
|
|
if [[ $failed -gt 0 ]]; then
|
|
isNotice "Backup of $app_name succeeded on $succeeded location(s), failed on $failed"
|
|
else
|
|
isSuccessful "Backup of $app_name succeeded on $succeeded location(s)"
|
|
fi
|
|
return 0
|
|
}
|