mirror of
https://github.com/UiO-Gaming/drift.git
synced 2026-11-05 13:56:46 +01:00
- deploy/uiogaming-deploy: forced command for github_deploy's SSH key. Pulls the repo and rebuilds one service from /srv/uiogaming/docker-compose.yml, fixing deploys that failed on container-name conflicts. - backup/backup_db.sh: nightly pg_dumpall of all databases, gzipped, 14-day retention. - cron/uiogaming.crontab: the uiogaming user's crontab. - Document the new deploy setup and the move to /srv/uiogaming. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 lines
1019 B
Bash
Executable File
25 lines
1019 B
Bash
Executable File
#!/bin/bash
|
|
# Nightly dump of all Postgres databases + roles, compressed.
|
|
# Installed on the server as /srv/uiogaming/.backups/backup_db.sh, run by cron (see ../cron/uiogaming.crontab).
|
|
# The rsync user pulls the backup folder to off-site storage every night at 03:00.
|
|
#
|
|
# Restore: gunzip -c backup_YYYY-MM-DD.sql.gz | docker exec -i postgres psql -U postgres
|
|
set -euo pipefail
|
|
|
|
BACKUP_DIR=/srv/uiogaming/.backups/postgres
|
|
KEEP_DAYS=14
|
|
|
|
log() { echo "$(date '+%Y-%m-%d %H:%M:%S') $*"; }
|
|
fail() { log "Backup FAILED: $*" >&2; rm -f "$BACKUP_FILE"; exit 1; }
|
|
|
|
mkdir -p "$BACKUP_DIR"
|
|
BACKUP_FILE="$BACKUP_DIR/backup_$(date +%F).sql.gz"
|
|
trap 'fail "error on line $LINENO"' ERR
|
|
|
|
log "Backing up all databases"
|
|
docker exec postgres pg_dumpall -U postgres | gzip > "$BACKUP_FILE"
|
|
[[ $(gunzip -c "$BACKUP_FILE" | tail -n 5) == *"cluster dump complete"* ]] || fail "dump incomplete"
|
|
log "Backup completed: $BACKUP_FILE ($(du -h "$BACKUP_FILE" | cut -f1))"
|
|
|
|
find "$BACKUP_DIR" -name 'backup_*.sql*' -mtime +"$KEEP_DAYS" -delete
|