[lug] help with the infamous rsync include/exclude patterns
blug at chinesetearoom.com
Fri May 13 16:02:19 MDT 2016
On Fri, 13 May 2016 11:21:57 -0600
Davide Del Vento <davide.del.vento at gmail.com> wrote:
> I have this question at
> if you prefer to answer there. Otherwise keep reading
> I need to rsync some directories from one machine to another, but only
> part of the tree. I think the easiest way to explain it would be to
> run, on the server, tree -f (which prints the full path of each file)
> and then grep'ing mon in the full path and rsynch'ing only the matches
> of grep. Actually I would be happy to do it that way, but I don't have
> shell access to the server, only rsync. Two step solution based on
> greping output of rsync --list-only is totally acceptable.
> It's actually simpler, because I also know that this mon appears only
> as a suffix to a directory (the hierarchy is pretty rigid), so I tried
> rsync --dry-run -vrlpt --include='*/' --include='**/*mon/'
> --exclude='*' --prune-empty-dirs
> but that did not match anything. Ditto for --include='*mon/' instead
> of the one with the double asterisk. Avoiding the --prune-empty-dirs
> matched all the directories but no files, which I think is my problem.
> So I tried to add an include pattern for some file extensions right
> before the exclude pattern (which I would rather not do because I
> don't want to track them all and they might change), but that simply
> matched all those files, including the ones not in the "mon" trees.
> And yes, I did see countless examples of people doing similar stuff,
> which helped me making some progress (i.e. what you can see above),
> but not solve the problem...
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: irc.hackingsociety.org port=6667 channel=#hackingsociety
How about this?
$ find toplevel | sort
$ rsync -arvm --include='*/' --include='*mon/***' --exclude='*' toplevel /tmp
$ find /tmp/toplevel | sort
Only files under *mon directories are copied.
More information about the LUG