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.

  • 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

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.

| improve this answer | |
  • 2
    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
  • One problem I got with using * was that --delete did not delete any files, since they were not part of the search. – thomasa88 Feb 10 '16 at 14:33
  • @thomasa88 Please see this answer. – Kamil Maciorowski Jul 26 '19 at 12:56

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.