Rsync specific directories

file-copyrsyncwildcards

Below are the directories of my directory structure.

I only want to run rsync on the content under the archive directory of any subdirectory and exclude everything else:

./
ap/
ap/aploader/
ap/aploader/archive/
ap/as400/
ap/as400/archive/
ce/
ce/archive/
edi/
edi/810/
edi/810/archive/
fin/
fin/adp/
fin/adp/archive/
gl/
gl/adp/
gl/adp/archive/
gl/as400/
gl/as400/archive/
gl/dcb/
gl/dcb/archive/
om/
om/pricelist/
om/pricelist/archive/
om/sygma/
om/sygma/archive/

The source and destination directories have the same directory structure but only archive directory need to rsync.

For example:

Everything under /xx/inbound/om/pricelist/archive needs to be copied to /yy/inbound/om/pricelist/archive
and
xx/inbound/om/sygma/archive needs to be copied to
/yy/inbound/om/sygma/archive, and so on…

I tried the following which doesn't work as I want it to:

rsync --include '**archive/***' --exclude '*' -avzh -avzh /xx/inbound/ /yy/inbound

Best Answer

I think the only thing you're missing is to initially include all directories leading to the archive dirs, ie. also --include='*/'. This is because excluding a directory (with '*') excludes everything below it

rsync --include='*/' --include='**archive/***' --exclude='*' -avzh /xx/inbound/ /yy/inbound

Apart from that, you shouldn't need 2 sets of '-avzh'

Related Question