LibrePortal/scripts/backup/engine/kopia_backup.sh
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

101 lines
3.1 KiB
Bash

#!/bin/bash
kopiaBackupAppToLocation()
{
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
kopiaEnvExport "$idx" || return 1
local host_tag="${CFG_INSTALL_NAME:-libreportal}"
local tags=("--tags" "app:$app_name" "--tags" "host:$host_tag" "--tags" "engine:libreportal")
[[ -n "$manifest_sha" ]] && tags+=("--tags" "manifest:$manifest_sha")
local loc_name
loc_name=$(resticLocationName "$idx")
isNotice "Snapshotting $app_name$loc_name (kopia)" >&2
# Kopia has no per-run --exclude; it reads .kopiaignore from the source
# tree. On the live path write the raw DB data dirs (made relative to the
# source) as ignore patterns, snapshot, then remove it so the rule never
# leaks into a later non-live backup of the same app.
local ignore_file="$source_path/.kopiaignore"
local wrote_ignore=false
if [[ -n "${backup_exclude_paths:-}" ]]; then
local rel
: | runFileWrite "$ignore_file"
while IFS= read -r p; do
[[ -z "$p" ]] && continue
rel="/${p#"$source_path"/}"
echo "$rel" | runFileWrite -a "$ignore_file"
done <<< "$backup_exclude_paths"
runFileOp chown "$docker_install_user":"$docker_install_user" "$ignore_file" 2>/dev/null
wrote_ignore=true
fi
local output
output=$(runBackupOp kopia snapshot create "$source_path" "${tags[@]}" --json 2>&1)
local rc=$?
[[ "$wrote_ignore" == true ]] && runFileOp rm -f "$ignore_file"
local snapshot_id
snapshot_id=$(echo "$output" | grep -oE '"id":\s*"[^"]+"' | head -1 | cut -d'"' -f4)
if [[ $rc -eq 0 ]]; then
isSuccessful "Backup created in $loc_name: ${snapshot_id:0:12}" >&2
echo "$snapshot_id"
else
isError "Kopia backup to $loc_name failed for $app_name" >&2
echo "$output" | tail -10 >&2
fi
kopiaEnvUnset
return $rc
}
kopiaBackupSystemToLocation()
{
local idx="$1"
local source_path="${configs_dir%/}"
if [[ ! -d "$source_path" ]]; then
isError "System config path missing: $source_path"
return 1
fi
kopiaEnvExport "$idx" || return 1
local host_tag="${CFG_INSTALL_NAME:-libreportal}"
local tags=("--tags" "system:config" "--tags" "host:$host_tag" "--tags" "engine:libreportal")
local loc_name
loc_name=$(resticLocationName "$idx")
isNotice "Snapshotting system config → $loc_name (kopia)" >&2
local output
output=$(runBackupOp kopia snapshot create "$source_path" "${tags[@]}" --json 2>&1)
local rc=$?
local snapshot_id
snapshot_id=$(echo "$output" | grep -oE '"id":\s*"[^"]+"' | head -1 | cut -d'"' -f4)
if [[ $rc -eq 0 ]]; then
isSuccessful "System config backed up to $loc_name: ${snapshot_id:0:12}" >&2
echo "$snapshot_id"
else
isError "Kopia system config backup to $loc_name failed" >&2
echo "$output" | tail -10 >&2
fi
kopiaEnvUnset
return $rc
}