20 lines
895 B
Bash
Executable File
20 lines
895 B
Bash
Executable File
#!/bin/sh
|
|
# Encrypted nightly Postgres backup for Datewise. Run from the app folder on the VPS.
|
|
# Setup once: openssl rand -hex 32 > /root/.datewise-backup-key && chmod 600 /root/.datewise-backup-key
|
|
# Cron (3 am): 0 3 * * * /opt/datewise/scripts/backup.sh >> /var/log/datewise-backup.log 2>&1
|
|
# Restore: openssl enc -d -aes-256-cbc -pbkdf2 -pass file:/root/.datewise-backup-key -in FILE | gunzip | \
|
|
# docker compose exec -T db psql -U datewise datewise
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
KEY=/root/.datewise-backup-key
|
|
DIR=/root/backups
|
|
mkdir -p "$DIR"
|
|
chmod 700 "$DIR"
|
|
OUT="$DIR/datewise-$(date +%F).sql.gz.enc"
|
|
docker compose exec -T db pg_dump -U datewise datewise | gzip | \
|
|
openssl enc -aes-256-cbc -pbkdf2 -salt -pass "file:$KEY" -out "$OUT"
|
|
chmod 600 "$OUT"
|
|
# keep 14 days
|
|
find "$DIR" -name 'datewise-*.sql.gz.enc' -mtime +14 -delete
|
|
echo "$(date -Is) backup ok: $OUT"
|