Rsync – How to Sync Only New Files

rsync

I am trying to set up rsync to synchronize my main web server to the remote server by adding newly generated file to the latter.

Here is the command that I use:

rsync -avh --update -e "ssh -i /path/to/thishost-rsync-key" remoteuser@remotehost:/foo/bar /foo/bar

But it seems that the web server actually transfers all files despite the '–update' flag. I have tried different flag combinations (e.g. omitting '-a' and using'-uv' instead) but none helped. How can I modify the rsync command to send out only newly added files?

Best Answer

From man rsync:

--ignore-existing       skip updating files that exist on receiver

--update does something slightly different, which is probably why you are getting unexpected results (see man rsync):

This forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file. (If an existing destination file has a modification time equal to the source file's, it will be updated if the sizes are different.)

Related Question