Created
July 24, 2018 20:10
-
-
Save FlorianHeigl/8d7114722492d6f2fe8479efc77481af to your computer and use it in GitHub Desktop.
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 -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