hitobito-kjv/deploy/backup.sh
KJV Bautzen d00151388d Täglicher Datenbank-Dump und Doku zur Sicherung 🤖
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 17:25:34 +02:00

26 lines
914 B
Bash
Executable file

#!/usr/bin/env bash
# Tägliche Sicherung der hitobito-Datenbank als pg_dump (konsistent, im Gegensatz zum
# Snapshot des laufenden Postgres). Die Dateien landen in /root/hitobito/backups und werden
# von der PBS-Sicherung des LXC (2x/Woche, danach Band) mitgenommen.
# Uploads (Volume hitobito_uploads) sichert PBS direkt mit.
set -euo pipefail
DIR=/root/hitobito/backups
KEEP_DAYS=14
FILE="$DIR/hitobito-$(date +%F_%H%M).sql.gz"
cd /root/hitobito
docker compose exec -T db pg_dump -U hitobito hitobito | gzip > "$FILE.tmp"
# Nur vollständige Dumps behalten
if gunzip -c "$FILE.tmp" | tail -n 5 | grep -q "PostgreSQL database dump complete"; then
mv "$FILE.tmp" "$FILE"
chmod 600 "$FILE"
else
rm -f "$FILE.tmp"
echo "FEHLER: Datenbank-Dump unvollständig" >&2
exit 1
fi
find "$DIR" -name "hitobito-*.sql.gz" -mtime +"$KEEP_DAYS" -delete
echo "$(date "+%F %T") OK $FILE $(stat -c %s "$FILE") Bytes"