Skip to main content

Exit Codes & Error Handling

Exit Codes

CodeMeaningAction
0SuccessAll good
1Syntax errorFix command
2Protocol mismatchUpgrade rsync
3File selection errorCheck paths
5Daemon start errorCheck rsyncd
10Socket I/O errorRetry
11File I/O errorCheck disk
12Protocol stream errorRetry
23Partial transfer (I/O)Check perms
24Files vanishedUsually safe
25Max-delete reachedIntentional
30TimeoutIncrease --timeout
35Daemon timeoutRetry
255SSH errorDebug SSH

Error Handling Patterns

# Basic check
rsync -av src/ dest/
if [ $? -ne 0 ]; then echo "FAILED"; fi

# One-liner for cron
rsync -av src/ dest/ || echo "Failed ($?) at $(date)" >> /var/log/rsync-errors.log

# Treat vanished files as OK
rsync -av src/ dest/; [ $? -eq 24 ] && true

# Retry 3 times on failure
for i in 1 2 3; do rsync -avzP src/ dest/ && break || sleep 60; done

# Smart error handling
rsync -av src/ dest/
case $? in
0|24) echo "OK" ;;
10|12|30|255) echo "Network error, retrying..."; sleep 60; rsync -avP src/ dest/ ;;
*) echo "Fatal error"; exit 1 ;;
esac

# Alert on failure
rsync -av src/ dest/ || \
curl -s -X POST -d '{"text":"rsync failed!"}' https://hooks.slack.com/YOUR/WEBHOOK
warning

Don't use set -e with rsync — exit code 24 (vanished files) will kill your script even though it's usually harmless.