Files
AdventureLog/scripts/restore.sh
Sean Morley 7f6bf1390a Add Docker and environment configuration files for AdventureLog
- Introduced .dockerignore to exclude unnecessary files from Docker context.
- Added .env.aio.example for minimal configuration of the AdventureLog All-in-One setup.
- Updated .env.example to include optional SITE_URL and GUNICORN_WORKERS settings.
- Enhanced deploy.sh script for improved deployment flexibility and backup options.
- Updated docker-compose files to use PostGIS 16-3.5 and added health checks for services.
- Created docker-compose.aio.yml for All-in-One deployment configuration.
- Improved health checks and service dependencies in docker-compose.dev.yml and docker-compose.yml.
- Added GitHub workflows for building and pushing Docker images, including smoke tests for AIO setup.
2026-06-06 18:54:25 -04:00

108 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# Restore AdventureLog from a backup created by scripts/backup.sh.
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <backup-directory>" >&2
echo "Example: $0 backups/20260101-120000" >&2
exit 1
fi
BACKUP_DIR="$1"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$SCRIPT_DIR"
if [[ ! -d "$BACKUP_DIR" ]]; then
echo "ERROR: Backup directory not found: $BACKUP_DIR" >&2
exit 1
fi
COMPOSE_FILE="${COMPOSE_FILE:-}"
if [[ -z "$COMPOSE_FILE" ]]; then
if [[ -f .env.aio ]] && [[ ! -f .env ]]; then
COMPOSE_FILE="docker-compose.aio.yml"
elif [[ -f .env.aio ]] && [[ -f docker-compose.aio.yml ]] && [[ "${ADVENTURELOG_COMPOSE:-}" == "aio" ]]; then
COMPOSE_FILE="docker-compose.aio.yml"
else
COMPOSE_FILE="docker-compose.yml"
fi
fi
ENV_FILE="${ENV_FILE:-}"
case "$COMPOSE_FILE" in
*docker-compose.aio.yml*)
ENV_FILE="${ENV_FILE:-.env.aio}"
;;
*)
ENV_FILE="${ENV_FILE:-.env}"
;;
esac
if [[ -f "$ENV_FILE" ]]; then
COMPOSE=(docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE")
else
COMPOSE=(docker compose -f "$COMPOSE_FILE")
fi
resolve_compose_volume() {
local suffix="$1"
"${COMPOSE[@]}" volume ls -q | grep "${suffix}$" | head -n 1
}
MEDIA_VOLUME="$(resolve_compose_volume "adventurelog_media")"
if [[ -z "$MEDIA_VOLUME" ]]; then
MEDIA_VOLUME="$(resolve_compose_volume "media")"
fi
POSTGRES_USER="${POSTGRES_USER:-adventure}"
POSTGRES_DB="${POSTGRES_DB:-database}"
if [[ -f .env ]]; then
# shellcheck disable=SC1090
set -a
source .env
set +a
elif [[ -f .env.aio ]]; then
# shellcheck disable=SC1090
set -a
source .env.aio
set +a
fi
echo "Stopping AdventureLog containers..."
"${COMPOSE[@]}" down
if [[ -f "$BACKUP_DIR/.env" ]]; then
cp "$BACKUP_DIR/.env" .env
elif [[ -f "$BACKUP_DIR/.env.aio" ]]; then
cp "$BACKUP_DIR/.env.aio" .env.aio
fi
echo "Starting database..."
"${COMPOSE[@]}" up -d db
sleep 5
if [[ -f "$BACKUP_DIR/database.sql" ]]; then
echo "Restoring database..."
"${COMPOSE[@]}" exec -T db psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
cat "$BACKUP_DIR/database.sql" | "${COMPOSE[@]}" exec -T db psql -U "$POSTGRES_USER" -d "$POSTGRES_DB"
fi
if [[ -f "$BACKUP_DIR/media.tar.gz" ]]; then
if [[ -z "$MEDIA_VOLUME" ]]; then
echo "ERROR: media volume not found; cannot restore media" >&2
exit 1
fi
echo "Restoring media volume..."
docker run --rm \
-v "${MEDIA_VOLUME}:/data" \
-v "$(realpath "$BACKUP_DIR"):/backup:ro" \
alpine:3.21 \
sh -c "rm -rf /data/* && tar xzf /backup/media.tar.gz -C /data"
fi
echo "Starting AdventureLog..."
"${COMPOSE[@]}" up -d
echo "Restore complete."