Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to exclude a directory tree as part of an rsync command embedded in a bash script approximately like this:

$OPTIONS="-rl --exclude 'Some Parent Directory/Another Directory'"

rsync $OPTIONS $SOURCEDIR a@b.com:/SomeTargetDir

My aim is to sync all of $SOURCEDIR into /SomeTargetDir on the target machine, with the exception of everything under Some Parent Directory/Another Directory. However, I keep seeing errors of this form:

rsync: link_stat "/Users/myusername/Parent\" failed: No such file or directory (2)

I assume this is related to escaping the exclude path, but I just can't seem to get it right: every combination of \\, \ and so on that I try doesn't seem right. How can I write the exclude rule correctly?

I don't want to use --exclude-from unless I absolutely have to.

I am using rsync version 3.0.9 on OS X 10.8, syncing to Ubuntu 12.04 over SSH.

share|improve this question

1 Answer 1

Exclude matches patterns too. So try it like this:

$OPTIONS="-rl --exclude '*/Another Directory'"
rsync $OPTIONS $SOURCEDIR a@b.com:/SomeTargetDir

See this tutorial for more details.

EDIT #1

Another suggestion would be to try escaping double quotes rather than use single quotes:

$OPTIONS="-rl --exclude \"Some Parent\ Directory/Another\ Directory\""

The OP tried this alternative but it still didn't work for him in his case. It does work for me on Linux using version "3.0.8 protocol version 30" of rsync.

share|improve this answer
    
Thanks. That's not really what I wanted, though; I wanted to exclude only that specific subdirectory - 'Some Parent Directory/Another Directory'. –  Andrew Ferrier Apr 13 '13 at 13:16
    
it will also exclude Different Parent Directory/Another Directory, which isn't what I'm asking for. –  Andrew Ferrier Apr 13 '13 at 16:37
    
I cannot use double-quotes, as the environment variable in question ($OPTIONS) is already double-quoted. –  Andrew Ferrier Apr 13 '13 at 16:38
    
Good point, sorry. Nevertheless, I've just tried this and I still see the same error as before. –  Andrew Ferrier Apr 13 '13 at 17:01
    
What version of rsync are you using on MacOSX? Also can you show a little more of the directory tree, when I use the commands as I've suggested they work for me. Running rsync --version shows mine to be "3.0.8 protocol version 30". –  slm Apr 13 '13 at 17:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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