trying to rsync files of certain extension(*.sh), but the bash script below still transfer all the files, why?
from=/home/xxx rsync -zvr --include="*.sh" $from/* root@$host:/home/tmp/
Exclude Files and Directories from a List. When you need to exclude a large number of different files and directories, you can use the rsync --exclude-from flag. To do so, create a text file with the name of the files and directories you want to exclude. Then, pass the name of the file to the --exlude-from option.
Rsync with --ignore-existing-files: We can also skip the already existing files on the destination. This can generally be used when we are performing backups using the –link-dest option, while continuing a backup run that got interrupted. So any files that do not exist on the destination will be copied over.
The --exclude-from rsync option allows us to specify a file that contains a list of directories to be excluded. The file should be plaintext, so a simple . txt file will do. List one directory per line as you're compiling the list of directories that you want to exclude.
You need to add a --exclude all and it has to come after the --include
rsync -zvr --include="*.sh" --exclude="*" $from/* root@$host:/home/tmp/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With