librelad 34bd6d7936 feat(backup): kopia + borg system-config adapters (engine parity)
Mirror the restic system-config adapters for the other two engines, each in that
engine's own convention, so system backup/restore/status/retention work on any
location regardless of engine:

- kopia: BackupSystemToLocation (--tags system:config), SystemSnapshotsJson
  (filter tag system:config), RestoreSystemLatest, ForgetSystem (per-source policy
  on $configs_dir + maintenance).
- borg: BackupSystemToLocation (archive system-<host>-<ts>, comment system=config;
  no app is named "system" so the namespace can't collide), SystemSnapshotsJson
  (--glob-archives system-<host>-*), RestoreSystemLatest, ForgetSystem (prune the
  system-<host>-* glob).

No dispatcher change needed — engineBackupSystem/SystemSnapshotsJson/
RestoreSystemLatest/ForgetSystem already resolve <engine><fn> per location. All
three engines now define the full set; syntax clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-26 00:56:00 +01:00

94 lines
2.5 KiB
Bash

#!/bin/bash
borgBackupAppToLocation()
{
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
borgEnvExport "$idx" || return 1
local host_tag="${CFG_INSTALL_NAME:-libreportal}"
local archive
archive=$(borgArchiveName "$app_name" "$host_tag")
local comment="app=$app_name host=$host_tag engine=libreportal"
[[ -n "$manifest_sha" ]] && comment+=" manifest=$manifest_sha"
# Exclude the raw DB data dirs on the live path (see backup_db.sh).
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 to stderr; stdout is only the archive name for the caller's $().
isNotice "Snapshotting $app_name$loc_name (archive: $archive)" >&2
runBackupOp borg create \
--comment "$comment" \
--compression auto,zstd \
"${exclude_args[@]}" \
"::$archive" \
"$source_path"
local rc=$?
if [[ $rc -eq 0 ]]; then
isSuccessful "Backup created in $loc_name: $archive" >&2
echo "$archive"
else
isError "Backup to $loc_name failed for $app_name" >&2
fi
borgEnvUnset
return $rc
}
borgBackupSystemToLocation()
{
local idx="$1"
local source_path="${configs_dir%/}"
if [[ ! -d "$source_path" ]]; then
isError "System config path missing: $source_path"
return 1
fi
borgEnvExport "$idx" || return 1
local host_tag="${CFG_INSTALL_NAME:-libreportal}"
# No app is named "system", so the "system-<host>-*" archive namespace can't
# collide with an app's archives.
local archive
archive=$(borgArchiveName "system" "$host_tag")
local comment="system=config host=$host_tag engine=libreportal"
local loc_name
loc_name=$(resticLocationName "$idx")
isNotice "Snapshotting system config → $loc_name (archive: $archive)" >&2
runBackupOp borg create \
--comment "$comment" \
--compression auto,zstd \
"::$archive" \
"$source_path"
local rc=$?
if [[ $rc -eq 0 ]]; then
isSuccessful "System config backed up to $loc_name: $archive" >&2
echo "$archive"
else
isError "System config backup to $loc_name failed" >&2
fi
borgEnvUnset
return $rc
}