From 94e6a2d81195774374005f5d6f09cf825e4e0770 Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Sun, 23 Aug 2026 15:55:38 -0400 Subject: [PATCH] failover: tolerate rsync's benign vanished-file exit code in backup syncs Both sync-sd-backup.sh and sync-usb-backup.sh used set -e, so rsync returning exit 24 (partial transfer due to vanished source files -- expected on a live root, e.g. a container's shm socket disappearing mid-sync) aborted the script before it printed its own success message, even though the actual file transfer completed fully. Only exit 24 is now tolerated; any other rsync failure still aborts as before. Found running sync-sd-backup.sh today: it transferred all 919k files correctly but exited non-zero and skipped its completion line. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01YJfEELeh3ercpRBp8yYrYS --- failover/sync-sd-backup.sh | 14 +++++++++++++- failover/sync-usb-backup.sh | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/failover/sync-sd-backup.sh b/failover/sync-sd-backup.sh index f4439b9..94eb745 100755 --- a/failover/sync-sd-backup.sh +++ b/failover/sync-sd-backup.sh @@ -38,12 +38,24 @@ cleanup() { } trap cleanup EXIT +# rsync exit 24 ("partial transfer due to vanished source files") is expected on a +# live root — files like container shm sockets or in-progress logs routinely disappear +# mid-sync. Tolerate that one code; anything else is a real failure and still aborts. +rc=0 rsync -aHAX --numeric-ids --delete \ --info=progress2 \ --exclude=/proc/* --exclude=/sys/* --exclude=/dev/* --exclude=/run/* \ --exclude=/tmp/* --exclude=/mnt/* --exclude=/media/* --exclude=/lost+found \ --exclude=/boot/firmware/* --exclude=/swapfile \ --exclude=/etc/fstab --exclude=/etc/machine-id --exclude=/var/log/* \ - --stats / "$MOUNT_POINT/" + --stats / "$MOUNT_POINT/" || rc=$? + +if [ "$rc" -ne 0 ] && [ "$rc" -ne 24 ]; then + echo "rsync failed (exit $rc)." >&2 + exit "$rc" +fi +if [ "$rc" -eq 24 ]; then + echo "Note: some files vanished mid-sync (rsync exit 24) — normal on a live root." >&2 +fi echo "SD backup ($SD_ROOT_PART) synced from $root_src." diff --git a/failover/sync-usb-backup.sh b/failover/sync-usb-backup.sh index eb02ac8..4949b39 100755 --- a/failover/sync-usb-backup.sh +++ b/failover/sync-usb-backup.sh @@ -38,12 +38,24 @@ cleanup() { } trap cleanup EXIT +# rsync exit 24 ("partial transfer due to vanished source files") is expected on a +# live root — files like container shm sockets or in-progress logs routinely disappear +# mid-sync. Tolerate that one code; anything else is a real failure and still aborts. +rc=0 rsync -aHAX --numeric-ids --delete \ --info=progress2 \ --exclude=/proc/* --exclude=/sys/* --exclude=/dev/* --exclude=/run/* \ --exclude=/tmp/* --exclude=/mnt/* --exclude=/media/* --exclude=/lost+found \ --exclude=/boot/firmware/* --exclude=/swapfile \ --exclude=/etc/fstab --exclude=/etc/machine-id --exclude=/var/log/* \ - --stats / "$MOUNT_POINT/" + --stats / "$MOUNT_POINT/" || rc=$? + +if [ "$rc" -ne 0 ] && [ "$rc" -ne 24 ]; then + echo "rsync failed (exit $rc)." >&2 + exit "$rc" +fi +if [ "$rc" -eq 24 ]; then + echo "Note: some files vanished mid-sync (rsync exit 24) — normal on a live root." >&2 +fi echo "USB backup ($USB_ROOT_PART) synced from $root_src."