problems using --ignore-existing and filter rules

Matt McCutchen matt at mattmccutchen.net
Sat Dec 29 22:39:09 GMT 2007


On Fri, 2007-12-28 at 13:03 -0500, Douglas Wade Needham wrote:
> The command line used is one like the following, while chroot'ed into
> the sandbox, with the attached filter:
> 
>     rsync -OavzHn --filter="merge /.rsync/filter.dirs" --ignore-existing / viking:/
>     
> I have also confirmed it on the latest versions found in FC6 and
> CentOS 4.5, and 5.0.  In this case, I have copied things from under /
> into a directory such as /sandbox/rsync_test, added a /.rsync
> subdirectory to hold my test_rsync script and filter file, and after
> adding a few extra files and creating a /opt2 by renaming /opt,
> running rsync.  In each and every case, I find that /.rsync and /opt2
> are transferred even if listed in a protect rule.  And this is true
> regardless of whether or not the path specification start and/or ends
> in a slash.

Right.  As documented in the man page, the sole effect of a protect rule
is to stop a destination file (or directory) from being deleted if it is
extraneous.  To stop a destination file from being updated, use an
exclude rule.

> Now, as to why the protect rule vs. exclude rule is important, I want
> to use the filter.dirs file to protect areas which are not a part of
> the OS, such as application data, home directories and such with this
> file,

If you mean that you don't want these areas processed at all, use an
exclude rule.

> and then have another file protect things such as configuration
> files which are a part of the OS, and should not be pushed once they
> exist, but should be pushed to a server once the server is up and
> running with a minimal OS load.

The --ignore-existing option makes rsync leave existing files alone
throughout the destination.  Rsync does not provide a way to selectively
activate this behavior for some areas of the destination.  If you want
this behavior for certain areas, you can use two rsync runs: one with
--ignore-existing for those areas, and one without --ignore-existing
with those areas excluded.

Still, note that --ignore-existing operates at the level of individual
files; there is no way to tell rsync not to add new files to an existing
directory.  If you need that, then for the first run, instead of passing
--ignore-existing, you should run a list of the "configuration" areas
through a script on the destination machine that filters out those that
already exist and then pass the resulting list to rsync with
--files-from.

> (Now if only rsync offered a way to run commands on the remote server
> when certain files were updated...hehe).

You can accomplish this by using an rsync daemon on the destination with
a "post-xfer exec" script that parses the daemon's log for any relevant
updates and runs any appropriate commands.  Or you could use a system
administration tool such as Puppet
( https://reductivelabs.com/trac/puppet ) to run commands on a file
update whether the update was done via rsync or other means.

Matt



More information about the rsync mailing list