affects the path you need to use in your matching (in addition to
changing how much of the file tree is duplicated on the destination
host). The following examples demonstrate this.
Let’s say that we want to match two source files, one with an absolute
path of "/home/me/foo/bar", and one with a path of "/home/you/bar/baz".
Here is how the various command choices differ for a 2‐source transfer:
Example cmd: rsync ‐a /home/me /home/you /dest
+/‐ pattern: /me/foo/bar
+/‐ pattern: /you/bar/baz
Target file: /dest/me/foo/bar
Target file: /dest/you/bar/baz
Example cmd: rsync ‐a /home/me/ /home/you/ /dest
+/‐ pattern: /foo/bar (note missing "me")
+/‐ pattern: /bar/baz (note missing "you")
Target file: /dest/foo/bar
Target file: /dest/bar/baz
Example cmd: rsync ‐a ‐‐relative /home/me/ /home/you /dest
+/‐ pattern: /home/me/foo/bar (note full path)
+/‐ pattern: /home/you/bar/baz (ditto)
Target file: /dest/home/me/foo/bar
Target file: /dest/home/you/bar/baz
Example cmd: cd /home; rsync ‐a ‐‐relative me/foo you/ /dest
+/‐ pattern: /me/foo/bar (starts at specified path)
+/‐ pattern: /you/bar/baz (ditto)
Target file: /dest/me/foo/bar
Target file: /dest/you/bar/baz
The easiest way to see what name you should filter is to just look at
the output when using --verbose and put a / in front of the name (use
the --dry‐run option if you’re not yet ready to copy any files).
PER‐DIRECTORY RULES AND DELETE
Without a delete option, per‐directory rules are only relevant on the
sending side, so you can feel free to exclude the merge files themselves
without affecting the transfer. To make this easy, the ’e’ modifier
adds this exclude for you, as seen in these two equivalent commands:
rsync ‐av ‐‐filter=’: .excl’ ‐‐exclude=.excl host:src/dir /dest
rsync ‐av ‐‐filter=’:e .excl’ host:src/dir /dest
However, if you want to do a delete on the receiving side AND you want
some files to be excluded from being deleted, you’ll need to be sure
that the receiving side knows what files to exclude. The easiest way is
to include the per‐directory merge files in the transfer and use
--delete‐after, because this ensures that the receiving side gets all
the same exclude rules as the sending side before it tries to delete
anything:
rsync ‐avF ‐‐delete‐after host:src/dir /dest
However, if the merge files are not a part of the transfer, you’ll need
to either specify some global exclude rules (i.e. specified on the com‐
mand line), or you’ll need to maintain your own per‐directory merge
files on the receiving side. An example of the first is this (assume
that the remote .rules files exclude themselves):
rsync ‐av ‐‐filter=’: .rules’ ‐‐filter=’. /my/extra.rules’
‐‐delete host:src/dir /dest
In the above example the extra.rules file can affect both sides of the
transfer, but (on the sending side) the rules are subservient to the
rules merged from the .rules files because they were specified after the
per‐directory merge rule.
In one final example, the remote side is excluding the .rsync‐filter
files from the transfer, but we want to use our own .rsync‐filter files
to control what gets deleted on the receiving side. To do this we must
specifically exclude the per‐directory merge files (so that they don’t
get deleted) and then put rules into the local files to control what
else should not get deleted. Like one of these commands: