百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 网站模板(百分百源码网)>电脑软件>服务器> rsync详解之exclude排除文件
分享本文到:

rsync详解之exclude排除文件

发布时间:05/16 来源:未知 浏览: 关键词:
题目:怎样避开同步指定的文件夹? --exclude

rsync --exclude files and folders
http://articles.slicehost.com/2007/10/10/rsync-exclude-files-and-folders
很常见的状况:我想同步/下的 /usr /boot/ , 但是不想复制/proc /tmp 这些文件夹
要是想避开某个途径 直接增加--exclude 即可
比方--exclude “proc”
--exclude ‘sources'
Note: the directory path is relative to the folder you are backing up.
注意:这个途径必须是一个相对途径,不能是绝对途径

例子:源服务器/home/yjwan/bashshell有一个checkout文件夹
[root@CentOS5-4 bashshell]# ls -dl checkout
drwxr-xr-x 2 root root 4096 Aug 21 09:14 checkou
此刻想要完全避开复制这个文件夹内容怎么办?
指标服务器施行
rsync -av --exclude “checkout” yjwan@172.16.251.241:/home/yjwan/bashshell /tmp
将不会复制这个文件夹
[root@free /tmp/bashshell]# ls -d /tmp/bashshell/checkout
ls: /tmp/bashshell/checkout: No such file or directory

注意:

1事实上,系统会把文件和文件夹一视同仁,要是checkout是一个文件,同样不会复制

2 要是想避开复制checkout里面的内容,可以这么写--exclude “checkout/123”

3 切记不可写为 --exclude “/checkout”这样绝对途径
这样写 将不会以免checkout被复制
比方
[root@free /tmp/bashshell]# rsync -av --exclude “/checkout” yjwan@172.16.251.241:/home/yjwan/bashshell /tmp
receiving file list … done
bashshell/checkout/

4可以运用通配符 避开不想复制的内容
比方--exclude “fire*”
那么fire打头的文件或者文件夹全部不会被复制
5要是想要避开复制的文件过多,可以这么写
--exclude-from=/exclude.list

exclude.list 是一个文件,放置的位置是绝对途径的/exclude.list ,为了以免出题目,最佳设置为绝对途径。

里面的内容一定要写为相对途径

比方 我想避开checkout文件夹和fire打头的文件

那么/exclude.list 写为
checkout
fire*
然后施行下列下令,注意写为--exclude-from或者--exclude-from=都可以
但是不能为--exclude
rsync -av --exclude-from=”/exclude.list” yjwan@172.16.251.241:/home/yjwan/bashshell /tmp
检查效果:的确避开了checkout文件夹和fire打头的文件

题目:怎样盘算对照复制今后的文件数目是否准确呢?

1 查看差错日志,看是否复制时候出题目了
2在源服务器施行可晓得具体文件和文件夹的总个数
ls –AlR|grep “^[-d]”|wc
然后指标服务器在盘算一遍个数
看看数字是不是能对的上就ok了
对不上再研究怎么回事
3此刻的题目是:要是我运用了--exclude参数就费事了

我怎么晓得要复制几个文件?

首先,前面下令时候提到过一种写法,就是只要源地址,没有指标地址的写法,这种写法可以用来列出所有应当被复制的文件

那么用这个下令,可以盘算出这个/root/bashshell下面文件和文件夹数目

在服务器端施行

[root@CentOS5-4 bashshell]# rsync -av /root/bashshell/ |grep “^[-d]” | wc
62 310 4249
和ls 得到的效果一致的
[root@CentOS5-4 bashshell]# ls -AlR |grep “^[-d]“|wc
62 558 3731
因而,比方说我不要fire 打头的文件,可以在服务器端先这样盘算要复制的文件
[root@CentOS5-4 bashshell]# rsync -av --exclude “fire*” /root/bashshell/ |grep “^[-d]” | wc
44 220 2695
然后复制已往
看指标机器的文件和文件夹数目为
[root@free /tmp]# ls -AlR /tmp/bashshell/ |grep “^[-d]“|wc
44 396 2554
可以晓得2者是同步的

题目: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.

对于这个参数:

I frequently find myself adding the -P option for large transfers. It preserves partial transfers in case of interuption, and gives a progress report on each file as it's being uploaded.
I move large media files back and forth on my servers, so knowing how long the transfer has remaining is very useful.
•Previous Entry: nginx 天天定时切割Nginx日志的脚本
•Next Entry: 怎样开启MySQL的长途帐号 热门标签:dede模板 / destoon模板 / dedecms模版 / 织梦模板
责任编辑:i9OmO
打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有152人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助



订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板