Monitor rsync Backup Cron Jobs
Shell & BashThe Problem
rsync backups run nightly but can fail due to network issues, disk full errors, or SSH key problems. A missed backup might not be noticed until you need to restore.
The Solution
Wrap rsync with error checking and send status to CronRabbit. Track backup duration to spot network degradation early.
Common rsync Failures
rsync can fail silently in many ways: SSH authentication errors, disk quota exceeded on the remote, network timeouts, or partial transfers. Each produces a non-zero exit code that cron ignores.
Monitoring Pattern
Capture rsync's exit code and report it to CronRabbit. Use /start to track duration — a backup that suddenly takes 3x longer may indicate network or disk issues.
Code Examples
Monitored rsync backup
Bash#!/bin/bash
set -euo pipefail
PING="https://ping.cronrabbit.com/your-id"
curl -fsS -m 5 --retry 3 --retry-all-errors "$PING/start"
rsync -avz --delete \
-e "ssh -i /root/.ssh/backup_key" \
/data/ backup@remote:/backups/daily/
RSYNC_EXIT=$?
if [ $RSYNC_EXIT -eq 0 ]; then
curl -fsS -m 10 --retry 5 --retry-all-errors "$PING"
else
curl -fsS -m 10 --retry 5 --retry-all-errors "$PING/fail"
echo "rsync failed with exit code $RSYNC_EXIT"
exit $RSYNC_EXIT
fi