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>
82 lines
2.7 KiB
Bash
82 lines
2.7 KiB
Bash
#!/bin/bash
|
|
|
|
manifestCollect()
|
|
{
|
|
local app_name="$1"
|
|
local app_dir="$containers_dir$app_name"
|
|
|
|
local libreportal_commit
|
|
libreportal_commit=$(git -C "${install_scripts_dir%/scripts/}" rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
|
|
|
local compose_file=""
|
|
for candidate in "$app_dir/docker-compose.yml" "$app_dir/compose.yml"; do
|
|
[[ -f "$candidate" ]] && compose_file="$candidate" && break
|
|
done
|
|
|
|
local compose_hash="unknown"
|
|
[[ -n "$compose_file" ]] && compose_hash=$(sha256sum "$compose_file" 2>/dev/null | cut -d' ' -f1)
|
|
|
|
local images_json="[]"
|
|
if [[ -n "$compose_file" ]]; then
|
|
local images=()
|
|
while IFS= read -r line; do
|
|
local img
|
|
img=$(echo "$line" | sed -E 's/^[[:space:]]*image:[[:space:]]*["'\'']?([^"'\'' ]+)["'\'']?.*/\1/')
|
|
[[ -n "$img" ]] && images+=("\"$img\"")
|
|
done < <(grep -E '^[[:space:]]+image:' "$compose_file" 2>/dev/null)
|
|
if [[ ${#images[@]} -gt 0 ]]; then
|
|
images_json="[$(IFS=,; echo "${images[*]}")]"
|
|
fi
|
|
fi
|
|
|
|
local volumes_json="[]"
|
|
if [[ -d "$app_dir" ]]; then
|
|
local vols=()
|
|
while IFS= read -r d; do
|
|
[[ -n "$d" ]] && vols+=("\"$(basename "$d")\"")
|
|
done < <(find "$app_dir" -mindepth 1 -maxdepth 1 -type d 2>/dev/null)
|
|
if [[ ${#vols[@]} -gt 0 ]]; then
|
|
volumes_json="[$(IFS=,; echo "${vols[*]}")]"
|
|
fi
|
|
fi
|
|
|
|
local size_bytes
|
|
size_bytes=$(sudo du -sb "$app_dir" 2>/dev/null | awk '{print $1}')
|
|
[[ -z "$size_bytes" ]] && size_bytes=0
|
|
|
|
local file_count
|
|
file_count=$(sudo find "$app_dir" -type f 2>/dev/null | wc -l | tr -d ' ')
|
|
|
|
local strategy="${CFG_BACKUP_STRATEGY:-auto}"
|
|
declare -f backupResolveStrategy >/dev/null 2>&1 && strategy=$(backupResolveStrategy "$app_name")
|
|
|
|
local databases_json="[]"
|
|
if declare -f backupDbDescriptors >/dev/null 2>&1; then
|
|
local dbs=() desc kind container datadir path
|
|
while IFS= read -r desc; do
|
|
[[ -z "$desc" ]] && continue
|
|
IFS=':' read -r kind container datadir path <<< "$desc"
|
|
dbs+=("{\"kind\":\"$kind\",\"container\":\"$container\",\"path\":\"$path\"}")
|
|
done < <(backupDbDescriptors "$app_name")
|
|
[[ ${#dbs[@]} -gt 0 ]] && databases_json="[$(IFS=,; echo "${dbs[*]}")]"
|
|
fi
|
|
|
|
cat <<EOF
|
|
{
|
|
"version": 2,
|
|
"app": "$app_name",
|
|
"host": "${CFG_INSTALL_NAME:-libreportal}",
|
|
"created_at": "$(date -Iseconds)",
|
|
"libreportal_commit": "$libreportal_commit",
|
|
"engine": "restic",
|
|
"compose_hash": "$compose_hash",
|
|
"images": $images_json,
|
|
"volumes": $volumes_json,
|
|
"size_bytes": $size_bytes,
|
|
"file_count": $file_count,
|
|
"strategy": "$strategy",
|
|
"databases": $databases_json
|
|
}
|
|
EOF
|
|
}
|