Files
GTI_GERENCIADOR_FISCAL/deploy/hub/restore.sh
T

16 lines
854 B
Bash

#!/usr/bin/env sh
# Restore a Hub backup into PostgreSQL. DESTRUCTIVE for the current data: asks for confirmation.
# ./restore.sh ./backups/gti_fiscal_20260919_120000.dump
set -eu
[ $# -eq 1 ] || { echo "usage: $0 <backup.dump>" >&2; exit 2; }
FILE="$(basename "$1")"
COMPOSE="docker compose -f docker-compose.prod.yml --env-file .env"
[ -s "${BACKUP_DIR:-./backups}/$FILE" ] || { echo "backup not found in ${BACKUP_DIR:-./backups}: $FILE" >&2; exit 1; }
printf "This REPLACES the current Hub database with %s. Type RESTORE to continue: " "$FILE"
read -r answer
[ "$answer" = "RESTORE" ] || { echo "aborted"; exit 1; }
$COMPOSE stop fiscal-hub
$COMPOSE exec -T postgres pg_restore -U gti -d gti_fiscal --clean --if-exists --no-owner "/backups/$FILE"
$COMPOSE up -d fiscal-hub # migrations run at start (alembic upgrade head)
echo "restore ok: $FILE"