Skip to content

Instantly share code, notes, and snippets.

@stiliajohny
Created October 21, 2021 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stiliajohny/b65cf2c61fa88a246cbc2242adb82a79 to your computer and use it in GitHub Desktop.
Save stiliajohny/b65cf2c61fa88a246cbc2242adb82a79 to your computer and use it in GitHub Desktop.
rsync script with max retries
#!/bin/bash
### ABOUT
### Runs rsync, retrying on errors up to a maximum number of tries.
### Simply edit the rsync line in the script to whatever parameters you need.
# Trap interrupts and exit instead of continuing the loop
trap "echo Exited!; exit;" SIGINT SIGTERM
MAX_RETRIES=50
i=0
# Set the initial return value to failure
false
while [ $? -ne 0 -a $i -lt $MAX_RETRIES ]
do
i=$(($i+1))
rsync -avz --progress --partial -e $1 $2
done
if [ $i -eq $MAX_RETRIES ]
then
echo "Hit maximum number of retries, giving up."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment