rsync : transferring files in one direction only

Is it possible to use rsync to copy files in one direction only?

For example, suppose we have:

left/a.txt

right/a.txt

where the files are initially identical.

If one then modifies right/a.txt, then:

rsync -avv left/ right/

will copy right/a.txt onto left/a.txt.

Is it possible to restrict rsync to only copying from left/ to right/ (i.e. prevent it from copying from right/ to left/)?


Solution 1:

You misunderstand rsync. This command:

rsync -avv left/ right/ 

will not sync anything in right to left. It will, as @atbg says, only sync left to right. Rsync is not a bi-directional syncer. It syncs the dest with the source.

Man page for reference: http://linux.die.net/man/1/rsync

Solution 2:

It should be rsync [OPTION...] SRC... [DEST] so it does work in that direction (unless you switch dest and src).

left/a.txt should be copied to right/a.txt:

$ echo 'left' > left/a.txt
$ echo 'right' > right/a.txt
$ cat left/a.txt && cat right/a.txt
left
right
$ rsync -avv left/ right/
sending incremental file list
delta-transmission disabled for local transfer or --whole-file
a.txt
total: matches=0  hash_hits=0  false_alarms=0 data=5

sent 95 bytes  received 34 bytes  258.00 bytes/sec
total size is 5  speedup is 0.04
$ cat left/a.txt && cat right/a.txt
left
left

If there are specific files you don't want included by rsync take a look at --exclude=PATTERN and --exclude-from=FILE.