How to rsync only some files in some directories

rsync

I'm trying to sync all *.jpg files from /var/www/data/models/days/ + some other directories from /var/www/data root.

I do:


rsync -az --delete --include='/models' --include='*.jpg' --exclude='*' $SRC::/var/www/data /var/www/data

but it doesn't sync anything. What am I doing wrong?

NOTE: I don't want to change the source or target to include /models/days as I need some other directories with the same filename matching (*.jpg).

Best Answer

You've included /models in the traversal, but none of its subdirectories. If a directory is excluded, rsync doesn't traverse it, so none of its contents can be included.

Use --include='*/' to include all subdirectories, and -m to not copy directories that would end up empty. For more information, see Rsync filter: copying one pattern only

Related Question