#!/bin/bash set -euo pipefail # Mealie Restore Smoke Test # # Borg-Extract der App-Daten + pg_restore des mealie.dump in isoliertes # Test-Postgres + Mealie-Boot + HTTP-Smoke. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" . "$SCRIPT_DIR/common.sh" WHATIF=0 KEEP_DATA=0 for arg in "$@"; do case "$arg" in --what-if) WHATIF=1 ;; --keep-data) KEEP_DATA=1 ;; *) echo "Unknown argument: $arg" >&2; exit 1 ;; esac done RESTORE_ROOT="/mnt/user/backups/restore-lab/mealie" REPORT_ROOT="/mnt/user/backups/restore-reports" EXTRACT_DIR="$BORG_RESTORE_HOST_ROOT/mealie-extract" COMPOSE_FILE="$SCRIPT_DIR/mealie-compose.test.yml" REPORT_FILE="$REPORT_ROOT/mealie-$(date +%F).md" DUMP_HOST_PATH="/mnt/user/backups/borg/dumps/latest/mealie.dump" if [ "$WHATIF" -eq 1 ]; then cat <&2 exit 1 fi # Stufe 1: App-Daten aus Borg borg_extract "/restore/mealie-extract" "local/appdata/mealie/data" if [ ! -d "$EXTRACT_DIR/local/appdata/mealie/data" ]; then echo "Mealie data path missing in Borg archive" >&2 exit 1 fi cp -a "$EXTRACT_DIR/local/appdata/mealie/data/." "$RESTORE_ROOT/data/" chmod -R a+rwX "$RESTORE_ROOT/data" # Stufe 2: Test-Postgres hochfahren + Dump einspielen docker compose -f "$COMPOSE_FILE" up -d restoretest-mealie-postgres >/dev/null until docker exec restoretest-mealie-postgres pg_isready -U mealie -d mealie >/dev/null 2>&1; do sleep 2 done restore_ok=0 for attempt in $(seq 1 12); do if docker exec -i restoretest-mealie-postgres \ pg_restore -U mealie -d mealie --clean --if-exists --no-owner --no-privileges \ < "$DUMP_HOST_PATH" 2>/tmp/mealie-pg-restore.err; then restore_ok=1 break fi if grep -qiE "starting up|shutting down|connection refused" /tmp/mealie-pg-restore.err; then sleep 5 continue fi if grep -qiE "FATAL|PANIC" /tmp/mealie-pg-restore.err; then cat /tmp/mealie-pg-restore.err >&2 exit 1 fi restore_ok=1 break done if [ "$restore_ok" -ne 1 ]; then cat /tmp/mealie-pg-restore.err >&2 exit 1 fi # Stufe 3: Mealie starten docker compose -f "$COMPOSE_FILE" up -d restoretest-mealie >/dev/null http_status="" for _ in $(seq 1 60); do http_status="$(curl -s -o /tmp/mealie-body.html -w '%{http_code}' \ -L http://127.0.0.1:19925/api/app/about || true)" if [ "$http_status" = "200" ]; then break fi sleep 2 done if [ "$http_status" != "200" ]; then echo "Mealie HTTP smoke failed: status=$http_status" >&2 docker logs --tail 80 restoretest-mealie >&2 || true exit 1 fi # Rezept-Count als Sanity-Check recipe_count="$(docker exec restoretest-mealie-postgres \ psql -U mealie -d mealie -tAc \ "SELECT count(*) FROM recipes;" 2>/dev/null | tr -d '[:space:]' || echo "n/a")" write_report "$REPORT_FILE" < $REPORT_FILE"