9

When performing backups under Bash with rsync, I'm trying to exclude all dotfiles and hidden directories in the top directory, but not those in otherwise targeted directories. For example:

/copyme.c  
/.dontcopythisfile  
/.dontcopythisdirectory/or_its_contents  
/directory/.butcopymetoo

rsync -a --include=".includeme" --exclude=".*" . DEST fails to copy the desired dotfiles in subdirectories, but variations such as --exclude="./.*" also fail.

Suggestions? Does this require a filter rule as opposed to the simpler --exclude?

3 Answers3

13

You should use anchor, and in rsync the anchor character is '/'.

So in your string should be:

rsync -a --include="/.includeme" --exclude="/.*" ./ DEST
0

rsync -a --include="/*/.*" --exclude="/.*" --exclude="node_modules" ./ ../out This is what worked for me, just make sure the input directory is the current directory to work.

0

I usually prefer to create .rsync-filter files containing the patterns:

- /.*

That way,

rsync -hxDPavilyzHFF --stats --delete ./ remote:/backup/

is the ideal backup command. The filtering is done by the -FF flags.

Note that using this method, you can have various .rsync-filter files in various subdirectories, applying to their respective subtrees. You can override exclusions in subdirectories as well, using this method.

sehe
  • 450
  • 3
  • 9