deadhead-space-freight-tycoon/deploy/backup/backup.sh

14 lines
596 B
Bash
Executable File

#!/bin/sh
# One backup now (Step 13.3): a compressed pg_dump of the game database into
# /backups, then dumps older than BACKUP_KEEP_DAYS are deleted. Connection
# settings come from the PG* environment variables.
set -eu
stamp="$(date -u +%Y%m%dT%H%M%SZ)"
file="/backups/deadhead-$stamp.dump"
# Written under a temporary name, so a half-written dump never looks complete.
pg_dump --format=custom --file="$file.partial"
mv "$file.partial" "$file"
find /backups -maxdepth 1 -name 'deadhead-*.dump' -mtime +"${BACKUP_KEEP_DAYS:-14}" -delete
echo "backup: wrote $file ($(du -h "$file" | cut -f1))"