I’m sure there’s an order-of-include/exclude solution to this, but I want to sync a home directory for a user which has a mail
folder. I do not want the mail
folder, but if there happens to be another subfolder with the same name, I need that included.
For instance, a source directory with this structure:
mkdir -p {foo/mail,foo/public/mail}
touch {foo/mail/this,foo/public/that,foo/public/mail/theother}
foo
|- mail
| - this
- public
|- that
- mail
- theother
… with this rsync command to exclude the mail folder…
rsync -avP --exclude="mail/" foo/ bar
… creates the following bar
folder:
bar
- public
- that
I need to include that public/mail
folder WITHOUT prior knowledge of its presence, since I am not in control of its contents. Syncing the public
folder separately is also not feasible, since this is only an example; the foo
folder could contain countless unknown folders and files. I only know for certain that I want to exclude the mail
folder from the root of my sync source.