Rsync: How do I include/exclude a directory whose name contains a hyphen

I'm working on a script to selectively synchronize certain users' directories with those on a server using rsync (version 3.0.5 protocol version 30).  I am using the --exclude-from command option, and everything works, except when a directory I am specifying contains a hyphen.  Then I can't get a patten match and the directory (and all its children) will not sync.  I have tried to escape the hyphen with a backslash, and replace it with an ampersand or a dot or an asterisk to wild card it.  The command I am using is:

rsync -avze ssh --dry-run --exclude-from='/home/user/excl.tmp' server01:/usr2/ /home/user/usr2/

Examples of excl.tmp file.  This works:
+ /gale
+ /gale/tools
+ /gale/tools/**
- *

This doesn't work (it only syncs the directory named gale):
+ /gale
+ /gale/solver-alpha
+ /gale/solver-alpha/**
- *

Note that rsync will happily sync other files with a hyphen in the name, it just fails to pattern match them when they are specified in the exclude file.

Other details:  The local machine is running ubuntu 9.04, while the remote server is running RedHat Enterprise Linux 5.4
LVL 1
jwolterAsked:
Who is Participating?
 
jwolterAuthor Commented:
Update: just when I thought I was zeroing in on a bug in the code,  I suddenly realized why this wasn't working and it's embarrasingly simple.  It is because one time, early in my testing, I ran the command without the --dry-run argument.  So the directory in question, and its contents were already on the local machine.  rsync (correctly) determined that nothing needed to be transferred so it listed nothing in that directory to transfer.

0
 
woolmilkporcCommented:
How about
+ "/gale"
+ "/gale/solver-alpha"
+ "/gale/solver-alpha/**"
- *
wmp
0
 
jwolterAuthor Commented:
@woolmilkporc: enclosing in quotes seems to guarantee that nothing will match.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
bman21Commented:
what about using escapes?  such as:

+ /gale
+ /gale/solver\-alpha
+ /gale/solver\-alpha/**

--OR--

going with woolmilkporc suggestion try using a single quote instead of a double quotes
0
 
jwolterAuthor Commented:
@bman21: nope, escapes don't work, nor do single quotes.

I tried the same commands on a system running rsync version 2.6.8 and it worked, so I'm thinking this is a bug in 3.0.5.  I think there are newer versions out, so I'm going to try that.
0
 
jwolterAuthor Commented:
Update: the latest version, 3.0.7, doesn't fix the problem.  I think it's time to submit a bug report.
0
 
bman21Commented:
Makes sense.  Glad you figured it out!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.