LibrePortal/scripts/backup/engine/restic_backup.sh
librelad 875a60f90f LibrePortal v0.1.0 — initial release
A free, open, self-hosted app platform (GNU AGPLv3): one-click app deploys,
Traefik reverse proxy with automatic SSL, rootless Docker support, gluetun
VPN routing, and a web dashboard to manage it all.

Free & open forever to self-host; optional paid hosted services fund it.
See PROMISE.md.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-21 20:37:54 +01:00

80 lines
2.1 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")
local loc_name
loc_name=$(resticLocationName "$idx")
isNotice "Snapshotting $app_name$loc_name"
local output
output=$(sudo -E -u "$docker_install_user" restic backup \
--host "$host_tag" \
"${extra_tags[@]}" \
--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}"
echo "$snapshot_id"
else
isError "Backup to $loc_name failed for $app_name"
echo "$output" | tail -10
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
}