Monitor rsync jobs by exit value

On this page

rsync has a long list of exit values, and two of them are easy to mistake for success: 23 for a partial transfer due to an error and 24 for files that vanished at the source. Pass the value to CronMissed and decide which ones should raise an alert.

How can a scheduled job fail silently on rsync backups?

  • Exit value 23 means a partial transfer due to an error: some files were copied and some were not.
  • Exit value 24 means a partial transfer due to vanished source files. It is common on live directories, where a file is deleted during the run.
  • Exit value 30 is a timeout in data send or receive and 35 a timeout waiting for the daemon connection; both are typical of a network that dropped mid-transfer.
  • Exit value 25 means the --max-delete limit stopped the deletions, which is a deliberate safety stop that still leaves the destination out of date.
  • Run through cron without a tty, rsync over SSH fails if the key needs a passphrase, and the failure is an exit value that nobody reads.

What are the limits of rsync backups?

LimitWhat the documentation says
0Success.
23Partial transfer due to error.
24Partial transfer due to vanished source files.
25The --max-delete limit stopped deletions.
30, 35Timeouts in data transfer or in waiting for the daemon connection.

How do you add a CronMissed ping to rsync backups?

The script reports the start, runs rsync, and maps exit value 24 to success because vanished files are usual on a live source. Every other non-zero value is sent as it is.

backup-rsync.sh
#!/bin/sh
PING_URL="https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10"
curl -fsS --max-time 10 --retry 5 --retry-connrefused -o /dev/null "$PING_URL/start"
output=$(rsync -a --delete --max-delete=1000 /srv/data/ backup@backup-host:/srv/backup/data/ 2>&1)
status=$?
if [ "$status" -eq 24 ]; then status=0; fi
printf '%s\n' "$output" | tail -c 100000 | curl -fsS --max-time 10 --retry 5 --retry-connrefused -o /dev/null --data-binary @- "$PING_URL/$status"
exit $status

Which check settings fit rsync backups?

Create a cron check with the schedule of the job and a grace that fits the longest sync. Incremental runs are quick, but the first run after a long outage can take hours, so allow for that or add a start timeout. A --max-delete safety stop (25) is the useful failure to catch: it means something deleted far more than usual at the source.

How do you confirm the check works?

  1. Run the script by hand and confirm both pings.
  2. Point the destination at an unreachable host and confirm the check goes down with a non-zero value.
  3. Delete a file from the source in the middle of a test run and confirm that 24 is treated as success.

Sources

Questions and answers

Why treat 24 as success?
Because the files that vanished are no longer there to copy, and the rest was transferred. If vanished files should be an alert in your case, remove the line that maps it.
Can the ping include what rsync did?
Yes. The script sends the end of rsync's output as the ping body, up to 100 kB, so the ping log shows the last files and any error messages.
Know when this job stops

Create a check, add the ping to the job, and CronMissed alerts you the first time a run is late or reports a failure.

Start monitoring