Skip to content

Instantly share code, notes, and snippets.

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 FlorianHeigl/8d7114722492d6f2fe8479efc77481af to your computer and use it in GitHub Desktop.
Save FlorianHeigl/8d7114722492d6f2fe8479efc77481af to your computer and use it in GitHub Desktop.
#!/bin/bash -u
# lock down remote end? via:
# https://learninginlinux.wordpress.com/2009/05/07/rsync-fixed-server-side-options/
STOREDIR=/srv/blah/contents
NICE="ionice -c3 nice -n 19"
run_rsync()
{
# use -vv to gather options for remote server to put in .ssh/authorized_keys
# that way you can limit rsync to intended use (sender will be fixed)
$NICE rsync -arHLz --exclude="*/backup/*" --exclude="weblogs" shop.blah.com: .
return $?
}
loop_rsync()
{
SYNCED=no
TRIES=0
cd $STOREDIR || exit 1
while [ $SYNCED = "no" ]; do
if [ $TRIES -gt 20 ]; then
echo "Bailing out after 100 incomplete sync attempts"
break
fi
TRIES=$(( $TRIES + 1 ))
# call the actual sync, return code will be passed back
run_rsync
case $? in
# group return codes by types of issues, see man page
0|24)
SYNCED=yes
;;
1|2|3|4|5)
echo "rsync says we misconfigured it"
break
;;
# cases where a retry could help
10|11|12|14|20|23|30)
continue
;;
19)
echo "user aborted!"
exit 1
;;
*)
echo "unknown issue"
break
;;
esac
done
}
loop_rsync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment