一聚教程网:一个值得你收藏的教程网站

热门教程

rsync 排除文件和文件夹参数详解

时间:2022-06-30 18:11:50 编辑:袖梨 来源:一聚教程网


假设最开始的命令是这样的
rsync -e 'ssh -p 30000' -avl --delete --stats --progress demo@123.45.67.890:/home/demo /backup/

一、排除单独的文件夹和文件

要排除sources文件夹,我们可以添加 '--exclude' 选项:

--exclude 'sources'

命令是这样的:
rsync -e 'ssh -p 30000' -avl --delete --stats --progress --exclude 'sources' demo@123.45.67.890:/home/demo /backup/

要排除 "public_html" 文件夹下的 "database.txt" 文件:

--exclude 'public_html/database.txt'

命令是这样的:
rsync -e 'ssh -p 30000' -avl --delete --stats --progress --exclude 'sources' --exclude 'public_html/database.txt' demo@123.45.67.890:/home/demo /backup/

二、使用 '--exclude-from' 排除多个文件夹和文件

建立文件:
/home/backup/exclude.txt

在里面定义要排除的文件夹和文件
sources
public_html/database.*
downloads/test/*

使用指令:
--exclude-from '/home/backup/exclude.txt'

最后的命令如下:
rsync -e 'ssh -p 30000' -avl --delete --stats --progress --exclude-from '/home/backup/exclude.txt' demo@123.45.67.890:/home/demo /backup/


Rsync的其他几个常见参数

1
-z        –compress              compress file data during the transfer
--compress-level=NUM    explicitly set compression level
--skip-compress=LIST    skip compressing files with suffix in LIST
压缩传输,如果网络带宽不够,那么应该压缩以后传输,消耗的当然是机器资源,但是如果内网传输的话,文件数量不是很多的话,这个参数不必要的。
2
--password-file=FILE

前面说过了,只有远端机器是rsync服务器,才能用这个参数
如果你以为个FILE写的是ssh 登陆的密码,那就大错特错了,不少人犯了这个错误。
3
–stats: Adds a little more output regarding the file transfer status.
4
–progress: shows the progress of each file transfer. Can be useful to know if you have large files being backup up.

热门栏目