rsync between servers – how to filter by file extension

If you need to rsync some files over network, this is the command

rsync -c -az -ersync -c -e 'ssh -p 2020' --stats --progress --whole-file jan@myserver.com:data/files/ ~/data/files/

Script will connect to myserver.com on port 2020 and copy files from my home directory to local home directory.
If you want to access folder outside of your home directory, just add a slash after .com:

Filter by file extension

~# rsync -c -az -ersync -c -e 'ssh -p 2020' --stats --progress --whole-file --include="*/" --include='*.gif' --exclude="*" jan@myserver.com:data/files/ ~/data/files/

This will copy gifs only.
Always remember to combine exclude and include together – if you omit exclude parameter, your –include won’t have any affect.

Fastest rsync to copy millions of files between servers

rsync -a -e 'ssh -p 2020' --stats --whole-file jan@myserver.com:data/files/. ~/data/files

It doesn’t compress the file, doesn’t look for checksum difference, basically it just looks if file exists on new server – if it doesn’t copy it. Uses very little cpu and it skips building of file list

Write a Comment

Comment