Edit: /opt/mawid/scripts/backup.sh (714B)
#!/usr/bin/env bash
# Nightly database backup (PROJECT_PLAN Phase 7 task 2).
# Cron example (see RUNBOOK.md): 0 3 * * * cd /opt/mawid && ./scripts/backup.sh
set -euo pipefail
cd "$(dirname "$0")/.."
STAMP=$(date -u +%Y%m%d-%H%M%S)
OUT="backups/mawid-$STAMP.sql.gz"
mkdir -p backups
docker compose exec -T postgres pg_dump -U mawid -d mawid | gzip > "$OUT"
# Local retention: 14 days.
find backups -name 'mawid-*.sql.gz' -mtime +14 -delete
# Offsite copy when configured (any S3-compatible storage).
if [ -n "${BACKUP_S3_BUCKET:-}" ]; then
aws s3 cp "$OUT" "s3://$BACKUP_S3_BUCKET/mawid/" ${BACKUP_S3_ENDPOINT:+--endpoint-url "$BACKUP_S3_ENDPOINT"}
fi
echo "backup written: $OUT ($(du -h "$OUT" | cut -f1))"