Exclude all but include select folders

Matt McCutchen hashproduct+rsync at gmail.com
Sat Jun 30 15:12:59 GMT 2007


On 6/30/07, Adrian Marsh <Adrian.Marsh at ubiquisys.com> wrote:
> I'm trying to rsync up to some centos repositories, but I only want to
> pull down the i386 and i386_64 folders with their RPMs, I've tried
> various combinations and include and exclude, and I'm sure that the
> below should work, but it doesn't...
>
> SOURCE=rsync://mirror.stanford.edu/mirrors/centos
> rsync -avrt $SOURCE --include=i386/ --include=*/ --exclude=*
> /var/www/html/centos/
>
> I thought that the exclude at the end would block everything except the
> i386 contents, and according to the man page I'd need the include=*/ to
> make sure child folders of the root were included.

As the man page says, "include" really just means "don't exclude".
Even though i386/ itself is included, the individual files inside are
still subject to exclusion by the --exclude=* .  To fix the command,
add a triple-star to the --include=i386/ so it also matches all the
files inside the i386 directories, preempting the exclude rule:
--include=i386/*** .

You might also consider using --prune-empty-dirs so you don't get huge
subtrees of empty directories.

Matt


More information about the rsync mailing list