Handle Borg warning exit codes without aborting

This commit is contained in:
René Mathieu
2026-03-08 15:13:08 +01:00
parent 49368950ae
commit 02dfb054b5

View File

@@ -10,7 +10,7 @@
# nur dann beendet, wenn dieses Skript es selbst hochgebracht hat. # nur dann beendet, wenn dieses Skript es selbst hochgebracht hat.
# Zusätzlich: Schutz gegen parallele Ausführung per flock. # Zusätzlich: Schutz gegen parallele Ausführung per flock.
set -euo pipefail set -Eeuo pipefail
# ----------------------------- # -----------------------------
# Konfiguration # Konfiguration
@@ -149,6 +149,7 @@ on_error() {
local line_no="${1:-unknown}" local line_no="${1:-unknown}"
log "FEHLER in Zeile ${line_no}, Exit-Code ${exit_code}" log "FEHLER in Zeile ${line_no}, Exit-Code ${exit_code}"
send_pushover "Backup FEHLER auf $(hostname): Zeile ${line_no}, Exit-Code ${exit_code}" 1 send_pushover "Backup FEHLER auf $(hostname): Zeile ${line_no}, Exit-Code ${exit_code}" 1
trap - EXIT
cleanup cleanup
exit "$exit_code" exit "$exit_code"
} }
@@ -360,6 +361,26 @@ rsync_paperless_backup() {
# ----------------------------- # -----------------------------
# Borg: lokal sichern + Mirror auf CIFS # Borg: lokal sichern + Mirror auf CIFS
# ----------------------------- # -----------------------------
run_borg_allow_warning() {
local label="$1"
shift
local rc
set +e
"$@"
rc=$?
set -e
if [[ "$rc" -ge 2 ]]; then
log "FEHLER: ${label} fehlgeschlagen (Exit-Code ${rc})."
return "$rc"
fi
if [[ "$rc" -eq 1 ]]; then
log "WARNUNG: ${label} mit Warnungen beendet (Exit-Code 1), mache weiter."
fi
}
borg_local_backup() { borg_local_backup() {
log "== Borg lokal Backup -> $LOCAL_BORG_REPO ==" log "== Borg lokal Backup -> $LOCAL_BORG_REPO =="
@@ -379,7 +400,7 @@ borg_local_backup() {
local archive="agathe-$(hostname)-$(date +%F_%H%M%S)" local archive="agathe-$(hostname)-$(date +%F_%H%M%S)"
log "Platz lokal: $(df -h "$LOCAL_BORG_BASE" | tail -1)" log "Platz lokal: $(df -h "$LOCAL_BORG_BASE" | tail -1)"
borg create --stats --compression zstd,6 \ run_borg_allow_warning "borg create" borg create --stats --compression zstd,6 \
"$LOCAL_BORG_REPO::$archive" \ "$LOCAL_BORG_REPO::$archive" \
/ \ / \
/boot \ /boot \
@@ -405,14 +426,14 @@ borg_local_backup() {
--exclude /mnt/groot \ --exclude /mnt/groot \
--exclude-caches --exclude-caches
borg prune -v --list "$LOCAL_BORG_REPO" \ run_borg_allow_warning "borg prune" borg prune -v --list "$LOCAL_BORG_REPO" \
--keep-daily="$KEEP_DAILY" \ --keep-daily="$KEEP_DAILY" \
--keep-weekly="$KEEP_WEEKLY" \ --keep-weekly="$KEEP_WEEKLY" \
--keep-monthly="$KEEP_MONTHLY" \ --keep-monthly="$KEEP_MONTHLY" \
--prefix "agathe-$(hostname)-" --prefix "agathe-$(hostname)-"
if [[ "$BORG_CHECK" == "1" ]]; then if [[ "$BORG_CHECK" == "1" ]]; then
borg check -v --verify-data "$LOCAL_BORG_REPO" run_borg_allow_warning "borg check" borg check -v --verify-data "$LOCAL_BORG_REPO"
fi fi
log "Lokales Borg Backup fertig: $archive" log "Lokales Borg Backup fertig: $archive"