0

my rsync command looks like this:

rsync --update -rav --filter="merge $HOME/mergefilter.txt" ~/ (remote_destination):~/

My mergefilter.txt file looks like this:

+ /directory_1/***
+ /directory_2/***
+ /directory_etc/***
- /**

The rsync command works great and updates everything in the specified directory trees. However, I am looking to add some specifics to it. I am not sure of the necessary syntax, but for one of my directory trees, I want to only include certain files. For example, imagine my mergefilter.txt working like this:

+ /directory_1/***
+ /directory_2/*** --include="*.c++" --include="*.h" 
+ /directory_etc/***
- /**

So that when syncing the directory_2 directory tree (and its subdirectories), only .c++ and .h files are updated.

I have viewed other stackexchange pages asking similar questions, but none of them demonstrate how to use include when using a filter file. What would be the correct syntax here?

0

You are already using include; each line that begins with + is an include rule; every line that begins with - is an exclude rule.

If you want to include only specific files within a certain directory, then you have to spell it out unfortunately. Your filter file becomes:

+ /dir_1/***
+ /dir_2/
+ /dir_2/**.c++
+ /dir_2/**.h
+ /dir_2/**/
- /dir_2/**
+ /dir_etc/***
- /*

First you have to ensure that dir_2 is included: + /dir_2/.

Next you include all *.c++ and all *.h files within that dir_2; remember that ** matches all characters including slash.

Next you also have to include all directories within dir_2: + /dir_2/**/ otherwise the files within subdirectories aren't found, as those subdirectories are excluded.

Finally exclude all other files.

Note that you can also use per-directory merge files, so rsync will check every directory for a given filename and if found, use that file as an additional filter for that directory. See the -F option in the manpage.

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.