One way would be to make a list of all the files on target2, then do an
rsync to target1 using the "--exclude-from=" option to exclude all the files that already exist on target2. Without knowing what your directory structures look like it's hard to give precise instructions, but here's the general idea:
Code:
find /path/to/target2 -type f -printf '%P\n' >/tmp/t2files.txt
rsync -a --exclude-from=/tmp/t2files.txt /path/to/sourcedir/ /path/to/target1
rsync -a --existing /path/to/sourcedir/ /path/to/target2
The
find command stores all the paths to files on target2 (without the leading "/path/to/target2") on the temp file. The first
rsync skips all of the previously found files. The second
rsync updates only the files that already exist on target2.
Note that the trailing "/" on "/path/to/sourcedir/" is significant and causes
rsync to copy the
contents of the source directory and not the directory name. If the directory name itself is replicated on the target, then you should omit that trailing "/".
You should try this first using the "-n" (--dry-run) and "-v" (--verbose) options on the
rsync commands to make sure it's all working as expected.
This obviously breaks down if all of the new files won't fit on target1, but you did say "(either) target".