first commit
CI / lint-and-test (push) Canceled after 0s

This commit is contained in:
Alberto-Audrix committed 2026-07-28 08:55:05 +07:00
commit 32a36cceff
444 files changed
+67186

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env sh
# Daily PostgreSQL backup via Docker Compose (database service).
# Run from anywhere: uses project root next to this script.
# Cron example (2:15 AM): 15 2 * * * /path/to/repo/scripts/backup-postgres.sh
set -e
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
PROJECT_ROOT=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
cd "$PROJECT_ROOT"
BACKUP_DIR="${BACKUP_DIR:-$PROJECT_ROOT/backups}"
KEEP_DAYS="${KEEP_DAYS:-14}"
mkdir -p "$BACKUP_DIR"
STAMP=$(date +%Y%m%d-%H%M%S)
OUT="$BACKUP_DIR/dashboard_db-$STAMP.sql.gz"
# TCP + password avoids peer-auth issues when exec runs as non-postgres user
docker compose exec -T database sh -c \
'PGPASSWORD="$POSTGRES_PASSWORD" pg_dump -h 127.0.0.1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" --no-owner --no-acl' \
| gzip -c > "$OUT"
echo "Backup written: $OUT"
# Drop backups older than KEEP_DAYS (optional)
if [ -n "$KEEP_DAYS" ] && [ "$KEEP_DAYS" -gt 0 ] 2>/dev/null; then
find "$BACKUP_DIR" -maxdepth 1 -name 'dashboard_db-*.sql.gz' -type f -mtime "+$KEEP_DAYS" -delete 2>/dev/null || true
fi