backup: fix storage-backup oneshot falsely failing on success #212

Sammanfogat
supernaut sammanfogade 1 incheckning från fix/backup-storage-exit-status in i main 2026-07-23 14:59:20 +00:00
Ägare

Problem

bitborg-backup-storage.service exits non-zero (systemd failed) even when the restic backup
fully succeeds
. The cleanup EXIT trap's only command is [ "${rc}" -ne 0 ] && write_status 1;
on the success path (rc=0) the test is false → the compound returns 1, and as the trap's last
command it becomes the script's exit status. So the oneshot is marked failed on every good run.

Observed on the first production run: snapshot ... saved (8.9 GiB) and the success metric
gitborg_backup_storage_last_run_status=0 were both written, yet the unit reported
Result=exit-code / status=1/FAILURE. (The daily backup script avoids this only because its trap
has later commands that return 0 on the success path.)

Fix

Guard the metric write in an if block and exit "${rc}" explicitly at the end of the trap, so the
oneshot's exit status matches reality — 0 on success, the real non-zero on a genuine failure. The
node-exporter metric still drives alerting either way.

Impact

  • No data risk — backups were already succeeding (snapshot present in the restic repo); this only
    corrects the reported service status.
  • Alerting unaffected (the metric was already correct).
  • Follow-up to #211.
## Problem `bitborg-backup-storage.service` exits non-zero (systemd `failed`) **even when the restic backup fully succeeds**. The `cleanup` EXIT trap's only command is `[ "${rc}" -ne 0 ] && write_status 1`; on the success path (`rc=0`) the test is false → the compound returns 1, and as the trap's last command it becomes the script's exit status. So the oneshot is marked failed on every good run. Observed on the first production run: `snapshot ... saved` (8.9 GiB) and the success metric `gitborg_backup_storage_last_run_status=0` were both written, yet the unit reported `Result=exit-code` / `status=1/FAILURE`. (The daily backup script avoids this only because its trap has later commands that return 0 on the success path.) ## Fix Guard the metric write in an `if` block and `exit "${rc}"` explicitly at the end of the trap, so the oneshot's exit status matches reality — 0 on success, the real non-zero on a genuine failure. The node-exporter metric still drives alerting either way. ## Impact - **No data risk** — backups were already succeeding (snapshot present in the restic repo); this only corrects the reported service status. - Alerting unaffected (the metric was already correct). - Follow-up to #211.
supernaut lade till 1 incheckning 2026-07-23 14:49:01 +00:00
supernaut sammanfogade incheckning 7164e1fdce till main 2026-07-23 14:59:20 +00:00
supernaut tog bort grenen fix/backup-storage-exit-status 2026-07-23 14:59:20 +00:00
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-infra!212
Ingen beskrivning angiven.