rsync with particular file pattern

I'd like to rsync any files that end with 'rpt' under source dir called 'opt', and here is the command i tried:

rsync -avz --include='*.rpt' --exclude='*' /opt /tmp -n

but the list returned is a complete listing under opt. can anyone help out please?

Its surprising that !!

  1. Without slash at the end in SOURCE..
# rsync -avz --include='*.rpt' --exclude='*' /opt /tmp/2 -n
sending incremental file list

sent 10 bytes  received 12 bytes  44.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)
  1. With slash at the end in SOURCE.
# rsync -avz --include='*.rpt' --exclude='*' /opt/ /tmp/2 -n
sending incremental file list
./
a.rpt
b.rpt

sent 67 bytes  received 21 bytes  176.00 bytes/sec
total size is 8  speedup is 0.09 (DRY RUN)

Its quite opposite to what you are speaking !! And only *.rpt syncs when you have / at the end !

It's actually slightly more complicated then that - my rpt's are within recursive dirs under SOURCE. eg.

$ find /tmp/opt -name "*.rpt"
/tmp/opt/d/def.rpt
/tmp/opt/b.rpt
/tmp/opt/a.rpt
$ rsync -aruv --include='*.rpt' --exclude='*' /tmp/opt/ /tmp/2 -n
building file list ... done
created directory /tmp/2
./
a.rpt
b.rpt

sent 124 bytes  received 38 bytes  324.00 bytes/sec
total size is 0  speedup is 0.00

Note d/def.rpt is missing from the list.

But that said.... I'd finally GOT IT!!!

$ rsync -aruv --include="*/" --include="*.rpt" --exclude="*" /tmp/opt/ /tmp/2/ -n

-a, --archive archive mode, equivalent to -rlptgoD
-r, --recursive recurse into directories
-u, --update update only (don't overwrite newer files)
-v, --verbose increase verbosity

the first 'include' is to ensure recursiveness
the second 'include' is the actual inclusion rule
finally use an exclude to fence off everything else

The real trick is that 'include' and 'exclude' have to come in pair to work properly, so you either go : include <> then exclude <PATTERN>, or exclude <> then include <PATTERN>

Thanks heaps for the reply. Yous slash at the end of the SOURCE was a real big hint for me. Much appreciate! ': )