Files
Moonbase/scripts/db-backup.sh
2026-06-15 21:45:09 -05:00

25 lines
817 B
Bash
Executable File

#!/bin/sh
# Usage: ./scripts/db-backup.sh [output-file]
# Uses DATABASE_URL from environment (or .env if present).
# Example — local: DATABASE_URL="postgresql://bonnamoon@localhost:5432/moonbase_dev" ./scripts/db-backup.sh
# Example — remote: ssh into NAS and run via docker exec (see README)
set -e
# Load .env if present and DATABASE_URL not already set
if [ -z "$DATABASE_URL" ] && [ -f ".env" ]; then
export $(grep -v '^#' .env | grep DATABASE_URL | xargs)
fi
if [ -z "$DATABASE_URL" ]; then
echo "Error: DATABASE_URL is not set."
exit 1
fi
OUTFILE="${1:-backups/moonbase-$(date +%Y%m%d-%H%M%S).sql}"
mkdir -p "$(dirname "$OUTFILE")"
echo "Backing up to $OUTFILE ..."
pg_dump "$DATABASE_URL" --no-owner --no-privileges -f "$OUTFILE"
echo "Done. $(du -sh "$OUTFILE" | cut -f1) written to $OUTFILE"