Updating app-backup.sh and app-restore.sh to handle nextcloud data correctly.

This commit is contained in:
2026-02-08 21:49:45 +01:00
parent 144de4f393
commit 77b3b65bfb
2 changed files with 266 additions and 190 deletions

View File

@@ -53,6 +53,10 @@ fi
: "${MAIL_SUBJECT_PREFIX:=[app-backup]}"
: "${MAIL_INCLUDE_LOG_TAIL_LINES:=200}"
# OPTIONAL: allow wp excludes via config, e.g. WP_EXCLUDES=("nextcloud/" "foo/")
# If unset, we compute a safe default for your setup.
: "${WP_EXCLUDES_MODE:=auto}" # auto|manual
# ---------- State for report ----------
START_EPOCH="$(date +%s)"
STATUS="SUCCESS"
@@ -95,10 +99,7 @@ cleanup_old_local_archives() {
DELETED_LOCAL_LIST_FILE="$list_file"
: > "$list_file"
# collect files older than retention
# shellcheck disable=SC2016
while IFS= read -r -d '' f; do
# best-effort size
local sz
sz="$(stat -c '%s' "$f" 2>/dev/null || echo 0)"
DELETED_LOCAL_BYTES=$((DELETED_LOCAL_BYTES + sz))
@@ -108,7 +109,6 @@ cleanup_old_local_archives() {
if [[ "$DELETED_LOCAL_COUNT" -gt 0 ]]; then
echo "-- Local retention: deleting ${DELETED_LOCAL_COUNT} archive(s) older than ${LOCAL_RETENTION_DAYS} day(s) from ${ARCHIVE_DIR}"
# delete using the collected list to ensure count/bytes match what we report
while IFS= read -r f; do
rm -f -- "$f" || true
done < "$list_file"
@@ -356,14 +356,55 @@ echo "-- Collecting files via rsync..."
rsync_dir() {
local src="$1"
local dst="$2"
shift 2 || true
[[ -d "$src" ]] || die "Source directory missing: $src"
mkdir -p "$dst"
rsync -aHAX --numeric-ids --delete --info=stats2 "$src"/ "$dst"/
# Remaining args are exclude patterns like "nextcloud/"
local excludes=()
while [[ $# -gt 0 ]]; do
excludes+=("--exclude=$1")
shift
done
rsync -aHAX --numeric-ids --delete --info=stats2 \
"${excludes[@]}" \
"$src"/ "$dst"/
}
compute_wp_excludes() {
# Returns exclude patterns via stdout, one per line
if [[ "${WP_EXCLUDES_MODE}" == "manual" ]]; then
if declare -p WP_EXCLUDES >/dev/null 2>&1; then
for e in "${WP_EXCLUDES[@]}"; do
echo "$e"
done
fi
return 0
fi
# auto mode:
# If Nextcloud is enabled and sits inside WP_DIR (your setup), exclude "nextcloud/" from WP sync
if [[ "${ENABLE_NEXTCLOUD}" == "true" ]]; then
local wp="${WP_DIR%/}"
local nc="${NC_DIR%/}"
if [[ "$nc" == "$wp/nextcloud" ]]; then
echo "nextcloud/"
fi
fi
}
if [[ "${ENABLE_WORDPRESS}" == "true" ]]; then
echo "-- WordPress files: ${WP_DIR}"
rsync_dir "${WP_DIR}" "$STAGING_DIR/files/wordpress"
mapfile -t _wp_excludes < <(compute_wp_excludes || true)
if [[ "${#_wp_excludes[@]}" -gt 0 ]]; then
echo "-- WordPress excludes: ${_wp_excludes[*]}"
rsync_dir "${WP_DIR}" "$STAGING_DIR/files/wordpress" "${_wp_excludes[@]}"
else
rsync_dir "${WP_DIR}" "$STAGING_DIR/files/wordpress"
fi
fi
if [[ "${ENABLE_NEXTCLOUD}" == "true" ]]; then