Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With RSYNC, how do includes and excludes combine?

Tags:

rsync

I want to rsync everything in /Volumes/B/, except for Cache directories, which I want to exclude globally. Also, I don't want to rsync any other /Volume/

I have the following exclusion file:

+ /Volumes/B/***
- Cache/
- /Volumes/*

The first and 3rd line seem to work correctly, except that rsync also picks up all Cache dirs under /Volumes/B/... ( /Volumes/B/***/Cache/ )

What am I missing?

like image 344
eatloaf Avatar asked Oct 31 '11 22:10

eatloaf


People also ask

How does rsync include and exclude work?

Using the include Option As its name implies, this option will filter the files transferred and include files based on the value provided. However, the include option only works along with the exclude option. This is because the default operation for rsync is to include everything in the source directory.

How do I exclude in rsync?

Exclude Files and Directories from a List. When you need to exclude a large number of different files and directories, you can use the rsync --exclude-from flag. To do so, create a text file with the name of the files and directories you want to exclude. Then, pass the name of the file to the --exlude-from option.

Does rsync sync in both directions?

rsync works in one direction, so we need to run it twice to sync directories in both directions.


1 Answers

rsync reads the exclude file top down when traversing the directories.
When it visited the Caches dirs, rsync acted on the first matching pattern.
The first matching pattern was "+ /Volumes/B/*", so Cache was included.

The rule is: When having particular subdirectories, put them first.

Here 's a simple step by step explanation.

like image 120
Joao Figueiredo Avatar answered Oct 12 '22 23:10

Joao Figueiredo