Rsync is deleting excluded file

rsync

I'm having trouble excluding a file from rsync. The file in question is a configuration file that is specific to the machine it's on, so I have one version on my dev machine, and another on the production box.

I can get this to work with an exclude on the command line, but I'd prefer to get it working with per-dir rule files.

So given this stripped-down example:

/mydir/
/mydir/foo/
/mydir/foo/bar.txt                <-- this is the config. file
/mydir/foo/baz.txt
/mydir/foo/.rsync-filter

where .rsync-filter contains:

- bar.txt

with a working-dir of the parent of mydir, I attempt rsync:

$ rsync -rptFvv --delete mydir/ remote.example.com:/home/pryan/temp/rsynctest/
opening connection using: ssh remote.example.com rsync --server -vvtpre.iLs --delete . /home/pryan/temp/rsynctest/  (8 args)
sending incremental file list
[sender] hiding file foo/.rsync-filter because of pattern .rsync-filter [per-dir .rsync-filter]
[sender] hiding file foo/bar.txt because of pattern bar.txt [per-dir .rsync-filter]
delta-transmission enabled
foo/
deleting foo/bar.txt
foo/baz.txt is uptodate
total: matches=0  hash_hits=0  false_alarms=0 data=0

sent 119 bytes  received 107 bytes  90.40 bytes/sec
total size is 4  speedup is 0.02

Clearly, it is reading the .rsync-filter rule because it says it's "hiding foo/bar.txt", but I was under the impression a – meant exclude, which means hide and protect.

I'm fairly certain this is going to be something stupid (on my part), so go easy — I'm all ready and waiting to kick myself!! 😀

UPDATE: Forgot to mention, locally I'm running rsync 3.1.0 (on Ubuntu 14.04) and the remote is rsync 3.0.9 (on Debian 7).

Best Answer

You need P for protect instead of - for exclude in your .rsync-filter. Excluding it in a filter means it doesn't get looked for at the source side, and then --delete kicks in as the destination doesn't see it listed in the file list which is transmitted from the source.

Related Question