Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

So, I have a seemingly simple issue, but so far I haven't found a solution: I want to exclude the topmost directory from an rsync, while still syncing all its children. The particular issue is that I don't have permission to modify the times of the topmost directory, but want all the children to have properly sync'd times.

The rsync command I'm using is as follows:

rsync --exclude ./ -rlptDu ./ server.example.com:/usr/local/directory/

and server.example.com:/usr/local/directory/ looks like this:

drwxrws---  5 root   staff 24576 Jul  9 15:00 .

(my local user is a member of staff)

When I run rsync, I get the following error:

rsync: failed to set times on "/usr/local/directory/.": Operation not permitted (1)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]
make: *** [pub_to_mel_internal] Error 23

This is version 3.0.9 on the local machine and 3.0.7 on the remote, both machines running Debian.

share|improve this question
    
Are you familiar with the syntax in this example: wirespeed.xs4all.nl/mediawiki/index.php/… It allows you to include specific files/directories from an otherwise excluded directory. You might need to use an exclude file though. –  jippie Jul 9 '12 at 19:35
    
Yeah. The issue is that I can't seem to convince it to exclude the toplevel directory (specifically). I haven't had issues with mixing includes / excludes in the past, it just seems as though the toplevel is a special case. –  Steve Pomeroy Jul 9 '12 at 20:46

1 Answer 1

up vote 6 down vote accepted

I think rsync's filter rules can't match the toplevel directory, so it's always synchronized. A workaround is to synchronize all the files inside this directory instead of the directory itself.

rsync -rlptDu -- * server.example.com:/usr/local/directory/

Add .[!.]* after * if you have dot files in the topmost directory, and ..?* if you have file names beginning with two dots.

share|improve this answer
1  
Awesome, thanks! That works. The only downside of this technique is that it requires the shell to select all the files. If you have tons of files in the directory (which I don't in my case), it may choke. That could probably be fixed using xargs (although not with the --delete options). –  Steve Pomeroy Jul 9 '12 at 22:53

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.