So I use rsync to keep a remote directory up to date

On an older post about WinSCP Kamil Grabowski asked if I’d used rsync to keep remote files in sync.

I have, and use it more often than winscp or sshfs.

rsync is basically a smart copy utility – it can copy (sync) files between local or remote directories, and it will copy on the changed portions of files.

You can use it as a single invocation:

rsync -avr localdir remoteuser@remotehost:remotedir

You can also do it in a loop (but note that if you haven’t set up your SSH keys, you’ll be prompted for a password each time…):

while true; do rsync -avr localdir remoteuser@remotehost:remotedir; sleep 5; done

If you want it to not make a connection unless there are new files, you need to get a bit more complex:

set source=SOURCE_DIR
touch -t 197001010000 last # make a placeholder file as of 1970 so we can find newer files
while true
  if [ "`find $source -newer last -print`" ]
    touch last
    rsync -avrz $source $dest
    echo -ne .
  sleep 5

1 Comment »

  1. Nice airport transfer Said,

    September 4, 2016 @ 7:44 am

    Nice airport transfer…

    So I use rsync to keep a remote directory up to date…

Leave a Comment