-
-
Save mvdoc/1ad1303d533a7267839a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| ### ABOUT: | |
| ### Runs rsync, retrying on errors up to a maximum number of tries. | |
| ### | |
| ### Usage: ./rsync-retry.sh source destination | |
| ### Example: ./rsync-retry.sh [email protected]:~/* ~/destination/path/ | |
| ### | |
| ### INPORTANT: | |
| ### To avoid repeated password requests use public key authentication instead of passwords | |
| ### "ssh-keygen" (with no password), then "ssh-copy-id [email protected]" | |
| echo -n "Enter No. of retries to attempt... " | |
| read MAX_RETRIES | |
| echo -n "Recursive flag ON? (y/n)? " | |
| read YN | |
| if [[ $YN == "y" || $YN == "Y" ]]; then | |
| RFLAG=-r | |
| fi | |
| COUNT=0 | |
| # Trap interrupts and exit instead of continuing the loop | |
| trap "echo Ctl+C Detected... Exiting!; exit;" SIGINT SIGTERM | |
| # Set the initial return value to failure | |
| false | |
| while [ $? -ne 0 -a $COUNT -lt $MAX_RETRIES ] | |
| do | |
| COUNT=$(($COUNT+1)) | |
| false | |
| while [ $? -ne 0 ] | |
| do | |
| echo | |
| echo "Waiting for internet connection to come up..." | |
| echo | |
| ping -c 3 google.com | |
| done | |
| echo | |
| echo "Attempt No. $COUNT" | |
| echo | |
| rsync -vzP -e 'ssh -o "ServerAliveInterval 10"' $RFLAG $1 $2 | |
| done | |
| if [ $COUNT -eq $MAX_RETRIES ] | |
| then | |
| echo "Hit maximum number of retries($MAX_RETRIES), giving up." | |
| fi | |
| if [ $? -eq 0 ] | |
| then | |
| echo "Finished after $COUNT retries!!" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment