Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rsync exclude a directory but include a subdirectory

I am trying to copy a project to my server with rsync. I have project specific install scripts in a subdirectory

project/specs/install/project1

What I am trying to do is exclude everything in the project/specs directory but the project specific install directory: project/specs/install/project1.

rsync -avz --delete --include=specs/install/project1 \     --exclude=specs/* /srv/http/projects/project/ \      [email protected]:~/projects/project 

But like this the content of the specs directory gets excluded but the install/project1 directory does not get included.

I have tried everything but i just don't seem to get this to work

like image 228
user1036651 Avatar asked Nov 25 '11 14:11

user1036651


People also ask

How to exclude a directory from rsync?

The --exclude-from rsync option allows us to specify a file that contains a list of directories to be excluded. The file should be plaintext, so a simple . txt file will do. List one directory per line as you're compiling the list of directories that you want to exclude.

How to exclude multiple folders 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.

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.

Is rsync recursive?

The rsync tool can recursively navigate a directory structure and update a second location with any new/changed/removed files. It checks to see if files exist in the destination before sending them, saving bandwidth and time for everything it skips.


1 Answers

Sometime it's just a detail.

Just change your include pattern adding a trailing / at the end of include pattern and it'll work:

rsync -avz --delete --include=specs/install/project1/ \     --exclude=specs/* /srv/http/projects/project/ \     [email protected]:~/projects/project 

Or, in alternative, prepare a filter file like this:

$ cat << EOF >pattern.txt > + specs/install/project1/ > - specs/* > EOF 

Then use the --filter option:

rsync -avz --delete --filter=". pattern.txt" \     /srv/http/projects/project/ \     [email protected]:~/projects/project 

For further info go to the FILTER RULES section in the rsync(1) manual page.

like image 100
spider Avatar answered Sep 19 '22 23:09

spider