- backup.sh: pg_dump (custom format), media volume and .env in one archive with retention (KEEP), cron example - restore.sh: confirmation, restores .env if missing, pg_restore --clean in one transaction, replaces media, restarts the app - Fix: MEDIA_ROOT=/data/media in the image so photos land on the volume - README: installation, Nginx/Cloudflare client-IP setup, configuration table, AI and Instagram notes, update, backup, troubleshooting, security - Test settings independent of the local .env Co-Authored-By: Claude Opus 5.5 <[email protected]>
45 lines
1.4 KiB
Bash
Executable File
45 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# Restores an archive created by backup.sh. ALL current data is replaced.
|
|
#
|
|
# ./scripts/restore.sh backups/kochbuch-20261030-033000.tar.gz [--yes]
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
|
|
ARCHIVE=${1:-}
|
|
if [ -z "$ARCHIVE" ] || [ ! -f "$ARCHIVE" ]; then
|
|
echo "Aufruf: $0 <backup.tar.gz> [--yes]" >&2
|
|
exit 1
|
|
fi
|
|
if [ "${2:-}" != "--yes" ]; then
|
|
printf "Alle aktuellen Rezepte, Nutzer und Fotos werden durch das Backup ersetzt. Fortfahren? [j/N] "
|
|
read -r answer
|
|
case "$answer" in j|J|ja|Ja) ;; *) echo "Abgebrochen."; exit 1 ;; esac
|
|
fi
|
|
|
|
WORK=$(mktemp -d)
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
tar -C "$WORK" -xzf "$ARCHIVE"
|
|
|
|
if [ ! -f .env ]; then
|
|
cp "$WORK/env.backup" .env
|
|
chmod 600 .env
|
|
echo ".env aus dem Backup wiederhergestellt."
|
|
fi
|
|
|
|
echo "Starte Datenbank …"
|
|
docker compose up -d db
|
|
until docker compose exec -T db sh -c 'pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"' >/dev/null 2>&1; do sleep 2; done
|
|
|
|
echo "Stoppe App …"
|
|
docker compose stop app || true
|
|
|
|
echo "Spiele Datenbank ein …"
|
|
docker compose exec -T db sh -c 'pg_restore -U "$POSTGRES_USER" -d "$POSTGRES_DB" --clean --if-exists --no-owner --single-transaction' < "$WORK/db.dump"
|
|
|
|
echo "Spiele Fotos ein …"
|
|
docker compose run --rm --no-deps -T --entrypoint sh app -c 'find /data/media -mindepth 1 -delete && tar -C /data -xzf -' < "$WORK/media.tar.gz"
|
|
|
|
echo "Starte App …"
|
|
docker compose up -d app
|
|
echo "Wiederherstellung abgeschlossen."
|