I'm trying to backup a machine using rsync and after reading numerous SO QAs and the man pages, I'm still failing to understand how include/exclude precedence works so I can transfer the right set of files. Obfuscating the specific details, I'm attempting the following:
Include rescursively:
/home/erik/foo
/home/erik/bar
/home/erik/baz
Include /git rescursively, but exclude some specific subdirs, like /git/src/github.com/foo and /git/src/github.com/bar.
So far, the rsync command I think should accomplish this. It does not, and I've tried a number of variations that fail in different ways:
rsync -am \
--include='*/' \
--include='/home/erik/foo' \
--include='/home/erik/bar' \
--include='/home/erik/baz' \
--include='/git' \
--exclude='/git/bin' \
--exclude='/git/src/github.com/foo' \
--exclude='/git/src/github.com/bar' \
--exclude='*' \
/ nfs.example.com:/data/pool/backup/laptop
Some specific questions:
I have seen it suggested many times that the initial
--include='*/is necessary, although I'm not entirely sure why. I gather it has something to do with ensuring directories are expanded and followed(?). I also assume the final exclude is what excludes any file that doesn't match on the higher statements? Could someone elaborate on whether or not these are both necessary, and their positions are significant?I am unsure whether or not the directories need leading
/. I have seen hints that these paths are relative to the requested transfer root of/, which would suggest it should be something likehome/erik, but I have not had success with this either. Could someone expand on how this works?I'm unsure if a suffix
/is required in the paths if I want to include the directory and all subcontents?Could someone elaborate on whether or not the position of the params is actually significant, i.e., the first in the list to match will be applied?
Is there any reason I should prefer
--filter='+ X'over--include? Same for exclude?
/as the source for the copy -- are you really trying to copy your entire filesystem (with some exceptions), or just/home/erik? Also, is/gitreally at the top level of the system volume (as the/at the beginning implies), or somewhere else? - Gordon Davisson