backup: fix vzdump-vms exit code — EXIT-trap && short-circuit falsely failed OK runs

First live run produced a valid 40G dump and logged status=0, but the service
exited 1/FAILURE: cleanup() used `[ -n "$KILLED" ] && push_metrics 2 0`, and a
bash EXIT trap whose LAST command returns non-zero overrides the script's
`exit 0`. With KILLED empty the && short-circuits -> returns 1 -> a successful
backup is marked failed (would trip a vzdump staleness/failure alert). Switch to
daily-backup's `if…fi` idiom (returns 0 when not killed). Bug reproduced + fix
verified locally; redeployed to PVE + reset-failed.

[ci skip]

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Viktor Barzin 2026-06-09 21:26:23 +00:00
parent 83f418159a
commit bc37b16815

View file

@ -55,7 +55,10 @@ push_metrics() {
KILLED=""
cleanup() {
rm -f "${LOCKFILE}"
[ -n "${KILLED}" ] && push_metrics 2 0
# NB: must be `if…fi`, NOT `[ … ] && …` — a bash EXIT trap whose LAST command
# returns non-zero overrides the script's `exit 0`, so the `&&` short-circuit
# (when KILLED is empty) would falsely mark a successful backup as failed.
if [ -n "${KILLED}" ]; then push_metrics 2 0; fi
}
trap cleanup EXIT
trap 'KILLED=1; exit 143' TERM INT