Script-Ueberarbeitung aus dem Live-Betrieb nachcommittet: Runner-Stopp gegen das SQLite-Journal-Race, Dump als Stream (tar.gz statt zip), 3 Versuche mit Retry. README dokumentiert das neue Verfahren und den aktuellen Pausen-Zustand des Crons (Backlogs CFGMON-09). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
36 lines
1.4 KiB
Bash
Executable File
36 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# Naechtliches Gitea-Backup (Cron des Users rantanplan, kein sudo noetig).
|
|
# Rotation: Es bleibt NUR der neueste Dump auf dem Host -- die Platte (38G)
|
|
# traegt nicht mehr, aeltere Staende gehoeren off-host:
|
|
# scp -P 2248 rantanplan@188.245.193.243:/opt/backup/gitea-dump-<datum>.zip .
|
|
set -eu
|
|
|
|
BACKUP_DIR=/opt/backup
|
|
CONTAINER=thread-net-git-gitea-1
|
|
TARGET="$BACKUP_DIR/gitea-dump-$(date +%F).tar.gz"
|
|
|
|
# Runner pausieren: sein DB-Polling erzeugt sekuendlich SQLite-Journal-
|
|
# Dateien, an deren Verschwinden "gitea dump" beim Packen scheitert
|
|
# (stat gitea.db-journal: no such file). Start am Ende auch im Fehlerfall.
|
|
docker stop gitea-runner >/dev/null
|
|
trap 'docker start gitea-runner >/dev/null' EXIT
|
|
|
|
# Dump als Stream (-f -): keine Zwischendatei im Container -- die Platte
|
|
# traegt nur EINE Dump-Kopie plus den alten Stand waehrend der Rotation.
|
|
ok=""
|
|
for attempt in 1 2 3; do
|
|
if docker exec -u git -w /tmp "$CONTAINER" gitea dump -c /data/gitea/conf/app.ini --type tar -f - 2>>"$BACKUP_DIR/backup.log" | gzip > "$TARGET.tmp"; then
|
|
ok=1
|
|
break
|
|
fi
|
|
rm -f "$TARGET.tmp"
|
|
echo "$(date -Is) dump-Versuch $attempt fehlgeschlagen, retry..."
|
|
sleep 5
|
|
done
|
|
[ -n "$ok" ] || { echo "$(date -Is) backup FEHLGESCHLAGEN nach 3 Versuchen"; exit 1; }
|
|
mv "$TARGET.tmp" "$TARGET"
|
|
|
|
find "$BACKUP_DIR" -maxdepth 1 -name 'gitea-dump-*' ! -name "$(basename "$TARGET")" -delete
|
|
|
|
echo "$(date -Is) backup ok: $TARGET ($(du -h "$TARGET" | cut -f1))"
|