It would seem that my
rsync parameters are fine.
I had to add a parameter to deal with files that exist after a connection failure. The choices were
--update to avoid rewriting things already written. I am still not sure which one is better (perhaps someone knows) but in this case I went with with
--update after reading this https://askubuntu.com/questions/399904/rsync-has-been-interrupted-copy-from-beginning
- --update skip files that are newer on the receiver
- --ignore-existing skip updating files that already exist on receiver
The connection problem conundrum (flaky wifi etc.) was solved by continually calling rsync when an exit code is not zero, thereby forcing my process to continue until the transfer is a success. (unless I cut the power, lightning strikes my power lines, or I kill it using a signal)
To handle network disconnects, I used a
while [ 1 ]
while [ 1 ] has a caveat: using a signal like ctrl c for an interrupt (SIGINT) will not work unless you add an explicit check for any exit codes above 128 that calls
if [ "$?" -gt 128 ] ; then break
then you can check for rsync's exit code. Zero means all files have been moved.
elif [ "$?" -eq 0 ] ; then exit
Otherwise, the transfer is not complete.
else sleep 5
Script Example sync-music.sh
The rsync script assumes ssh passwordless key authentication.
while [ 1 ]
rsync -e 'ssh -p22'\
if [ "$?" -gt 128 ] ; then
echo "SIGINT detected. Breaking while loop and exiting."
elif [ "$?" -eq 0 ] ; then
echo "rsync completed normally"
echo "rsync failure. reestablishing connection after 5 seconds"