#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
BACKUP_DIR="$ROOT/backups"
mkdir -p "$BACKUP_DIR"

STAMP="$(date +%F-%H%M)"
FILE="$BACKUP_DIR/postgres-$STAMP.sql.gz"

docker compose -f "$ROOT/infra/docker/docker-compose.prod.yml" exec -T postgres \
  pg_dump -U "${POSTGRES_USER:-compton_app}" "${POSTGRES_DB:-compton}" | gzip > "$FILE"

echo "Backup written: $FILE"
