0
votes

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 like home/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?

1
Stackoverflow is for questions about programming, not general command-line tool usage; the Unix & Linux stackexchange or Superuser would be better places to ask about this (but look for similar existing questions first, and see if they help). Also, you've given / as the source for the copy -- are you really trying to copy your entire filesystem (with some exceptions), or just /home/erik? Also, is /git really at the top level of the system volume (as the / at the beginning implies), or somewhere else? - Gordon Davisson
@GordonDavisson I'm using / as the source for the copy to capture both /git (it is really at the top level of the system) and /home/erik, while filtering only what I need. I don't see an alternative to include both of these in a single command as their only shared node is the root of the filesystem. - eriknelson

1 Answers

0
votes

I'm unsure if there's a more native way to cross post an answer, but I asked on Stack Exchange and got this excellent answer that solved what I was trying to do perfectly, with context.