Last active
January 21, 2016 18:38
-
-
Save tsaavik/c8476dbaadfe7096c6db to your computer and use it in GitHub Desktop.
Automatic rsync retry with incremental (delay) backoff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Rsyncr (Rsync Retry) 2016 David Mcanulty | |
# Runs rsync, retrying on errors up to a maximum number of tries with incremental backoff (delay) | |
# Based on idea from https://gist.github.com/iangreenleaf/279849 by iangreenleaf 2011 | |
# Set your max rsync retries here | |
max_retries=50 | |
# Trap interrupts (ctrl-c) and exit instead of continuing the loop | |
trap "echo Exited!; exit;" SIGINT SIGTERM | |
if [[ $# -eq 0 ]]; then | |
echo "*** No arguments provided to $0 showing rsync help instead ***" | |
sleep 2; rsync --help | |
exit 1 | |
fi | |
read -rs -p "Optional remote rsync password(enter for none): " RSYNC_PASSWORD | |
i=0 | |
while [[ ${i} -le ${max_retries} ]] ; do | |
if rsync "$@" ;then | |
echo "Rsync exited successfully after ${i} retries" | |
break | |
else | |
i=$(($i+1)) | |
sleep ${i} | |
fi | |
done | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I thought about adding password handling for ssh connections, but you should just use ssh keys.