Cito
Cito

Reputation: 1709

Include folder with same name that other in exclude in rsync

So I have this code:

rsync \
   --archive \
   --verbose \
   --compress \
   --delete \
   --no-motd \
   --exclude=.git* \
   --exclude=.idea \
   --exclude=.tags \
   --exclude=vendor \
   --exclude=tags \
   --exclude=node_modules \
   --rsync-path="sudo rsync" \
   "${src}"/ \
   "${profile}":"${dst}"

And it works beautiful! But I have a problem... with this tree structure:

.
├── app
│   ├── vendor/
├── vendor/

It does not work. I want exclude only ./vendor but include ./app/vendor. I've tried with --include but the result is the same: app/vendor is excluded always.

Upvotes: 6

Views: 1523

Answers (1)

ams
ams

Reputation: 25599

There's two ways to do this:

  1. With --include:

    rsync \
       .... \
       --include=app/vendor \
       --exclude=vendor \
       ....
    

    I.e. put the --include before the --exclude

  2. With a more specific --exclude:

    rsync \
        .... \
        --exclude=/vendor \
        ....
    

    I.e. exclude only the vendor in the source directory root (not to be confused with the filesystem root).

The basic rule for include/exclude rules is that rsync will use the first rule that matches any given file. You put your specific rules at the top, and the general rules at the bottom. If you get them backward you'll find that your specific override does not work.

Upvotes: 12

Related Questions