0

I am trying to use include and exclude options in rsync to copy a directory structure, excluding most but not all of the subdirectories, based on a pattern in the directory names. But, it isn't working. It is trying to copy everything over instead of just the subfolders I want. Is my syntax wrong?

I have tried:

rsync -am --include='*/*/*MPRAGE*/' --exclude='*' /parent_directory/ /destination

Also:

rsync -am --include='*/' --include='*/*/*MPRAGE*/' --exclude='*' /parent/ /dest

MPRAGE is the pattern that is in the name of each folder I want copied. But these folders are three levels deep in the structure, and I want to keep the well-organized directory structure intact for these folders I want copied.

Thanks in advance for any tips.

Jordan Garner
  • 147
  • 1
  • 2
  • 9
  • I'd expect that pattern to try to copy *nothing*, not everything? – ams Sep 24 '15 at 09:31
  • What makes you say that? Because the --exclude='*' ? I thought include option circumvents the exclude. My dry-run is giving me everything - all directories and files, even directories that do not have MPRAGE in name. I'm trying to copy this post: http://stackoverflow.com/questions/9952000/using-rsync-include-and-exclude-options-to-include-directory-and-file-by-pattern – Jordan Garner Sep 24 '15 at 17:10
  • 1
    Including files in subdirectories only works if the directory itself is not excluded, which it is. See the examples in the man page. – ams Sep 24 '15 at 18:47
  • Thanks for this. I keep reading the man but I don't see what I'm doing wrong. I added one of my new attempts, still no dice. Should I try to exclude everything that doesn't contain MPRAGE? Maybe --exclude='!**MPRAGE*' ? – Jordan Garner Sep 24 '15 at 20:23
  • 1
    Your new example now selects all directories, but doesn't select any files, so I still would expect `--dry-run -v` to list no files (use `--include='*/*/*MPRAGE*/*'` to include the files in the MPRAGE directory). Perhaps you should show your dry run options also? – ams Sep 25 '15 at 09:08
  • Thanks for the fix to my second include! The weirdest thing keeps happening - it's trying to copy all files and directories in the parent directory. Also I just found out, by trying other things, that I have very limited permissions to change files on this drive. This might explain this wackyness. Thank you for your time and help with this, someday I might figure it out... – Jordan Garner Sep 26 '15 at 01:43

0 Answers0