45 lines
1.4 KiB
Bash
45 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
# Restores a Notizarr Postgres backup produced by scripts/backup.sh.
|
|
# DESTRUCTIVE: drops and recreates all data in the target database.
|
|
#
|
|
# Run from the deployment root:
|
|
# ./scripts/restore.sh backups/notizarr-db-20260101-120000.sql.gz
|
|
set -euo pipefail
|
|
|
|
POSTGRES_CONTAINER="${POSTGRES_CONTAINER:-notizarr-postgres-dev}"
|
|
POSTGRES_USER="${POSTGRES_USER:-notizarr}"
|
|
POSTGRES_DB="${POSTGRES_DB:-notizarr}"
|
|
COMPOSE_FILE="${COMPOSE_FILE:-docker/docker-compose.yml}"
|
|
DUMP_FILE="${1:-}"
|
|
|
|
if [ -z "$DUMP_FILE" ]; then
|
|
echo "Usage: $0 <path-to-backup.sql.gz>" >&2
|
|
exit 1
|
|
fi
|
|
if [ ! -f "$DUMP_FILE" ]; then
|
|
echo "Error: $DUMP_FILE not found." >&2
|
|
exit 1
|
|
fi
|
|
if [ ! -f "$COMPOSE_FILE" ]; then
|
|
echo "Error: $COMPOSE_FILE not found. Run this from the deployment root." >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "This will REPLACE all data in the '$POSTGRES_DB' database (container $POSTGRES_CONTAINER)."
|
|
read -r -p "Type 'yes' to continue: " CONFIRM
|
|
if [ "$CONFIRM" != "yes" ]; then
|
|
echo "Aborted."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Stopping notizarr (keeping postgres running) ..."
|
|
docker compose -f "$COMPOSE_FILE" stop notizarr
|
|
|
|
echo "Restoring $DUMP_FILE ..."
|
|
gunzip -c "$DUMP_FILE" | docker exec -i "$POSTGRES_CONTAINER" psql -U "$POSTGRES_USER" "$POSTGRES_DB"
|
|
|
|
echo "Starting notizarr back up ..."
|
|
docker compose -f "$COMPOSE_FILE" up -d notizarr
|
|
|
|
echo "Done. Check logs: docker compose -f $COMPOSE_FILE logs notizarr --tail=50"
|