3

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!! :D

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).

2

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.

  • 1
    Turns out this is wrong. Exclude is actually Hide (sender) and Protect (receiver). Hide will hide the file from appearing in the senders file-list, whilst Protect will prevent the receiver from deleting it. The reason why using Protect is wrong is because whilst is prevents it being deleted, it doesn't stop the file appearing in the senders file-list, and as a result, the local copy will be sent to the remote - which I don't want to happen! ..... – Peter Ryan Sep 28 '14 at 22:21
  • 1
    .... Exclude is the correct filter. However, the reason I was having problems is because I was working with a file hierarchy that already existed on both the local and remote machines, BUT the .rsync-filter I had just created, only existed on the local machine. As a result, the rsync-sender saw the filter and hide the file, but the rsync-receiver could not see the filter and still performed the delete. The reason why I thought your solution was correct was because when the .rsync-filter only exists on the sending side, using P does indeed prevent it from being deleted! ..... – Peter Ryan Sep 28 '14 at 22:24
  • 2
    ... But I do still really appreciate you taking the time to answer my long and rambling questions (and answers!) - it set me on the right path to the answer. Cheers! :D – Peter Ryan Sep 28 '14 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.