LibrePortal/scripts/backup/engine/borg_backup.sh
librelad d9f2feef05 feat(backup): consistent live database backups with auto strategy
Adds a logical-dump path so apps with a database can be backed up with zero
downtime and full consistency, instead of stopping the container.

- backup_db.sh: dump each declared DB live (mysqldump --single-transaction /
  pg_dump / sqlite3 .backup), exclude the raw data dir from the snapshot, and
  replay the dump on restore (pre-start rehydrate for sqlite, post-start load
  for server engines).
- Databases are declared via a 'libreportal.backup.db' compose label so the
  metadata travels with the app in the snapshot.
- New 'auto' strategy (now the default): live where a DB is dumpable or the app
  is marked live-safe, stop-snapshot-start otherwise. Explicit stop/pause/live
  remain as overrides.
- restic/borg/kopia adapters honour an exclude list on the live path.
- Manifest records the resolved per-app strategy and dumped databases.

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

52 lines
1.4 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")
isNotice "Snapshotting $app_name$loc_name (archive: $archive)"
sudo -E -u "$docker_install_user" 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"
echo "$archive"
else
isError "Backup to $loc_name failed for $app_name"
fi
borgEnvUnset
return $rc
}