rsync详解之exclude排除文件【转】

rsync详解之exclude排除文件

问题:如何避开同步指定的文件夹?  --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文件夹

[[email protected] bashshell]# ls -dl checkout

drwxr-xr-x 2 root root 4096 Aug 21 09:14 checkou

现在想要完全避开复制这个文件夹内容怎么办?

目标服务器执行

rsync -av --exclude “checkout” [email protected]:/home/yjwan/bashshell /tmp

将不会复制这个文件夹

[[email protected] /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被复制

比如

[[email protected] /tmp/bashshell]# rsync -av --exclude “/checkout” [email protected]:/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” [email protected]:/home/yjwan/bashshell /tmp

检查结果:确实避开了checkout文件夹和fire打头的文件

问题:如何计算对比复制以后的文件数量是否正确呢?
1 查看错误日志,看是否复制时候出问题了

2在源服务器执行可知道具体文件和文件夹的总个数

ls –AlR|grep “^[-d]”|wc

然后目标服务器在计算一遍个数

看看数字是不是能对的上就ok了

对不上再研究怎么回事

3现在的问题是:如果我使用了--exclude参数就麻烦了

我怎么知道要复制几个文件?
首先,前面命令时候提到过一种写法,就是只有源地址,没有目标地址的写法,这种写法可以用来列出所有应该被复制的文件
那么用这个命令,可以计算出这个/root/bashshell下面文件和文件夹数量

在服务器端执行

[[email protected] bashshell]# rsync -av /root/bashshell/ |grep “^[-d]” | wc

62     310    4249

和ls 得到的结果一致的

[[email protected] bashshell]# ls -AlR |grep “^[-d]“|wc

62     558    3731

因此,比如说我不要fire 打头的文件,可以在服务器端先这样计算要复制的文件
[[email protected] bashshell]# rsync -av --exclude “fire*” /root/bashshell/ |grep “^[-d]” | wc

44     220    2695

然后复制过去

看目标机器的文件和文件夹数量为

[[email protected] /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的远程帐号

转自

rsync详解之exclude排除文件 -娜一片天空-51CTO博客 https://blog.51cto.com/wanwentao/582432

原文地址:https://www.cnblogs.com/paul8339/p/11307365.html

时间: 2024-08-05 23:04:54

rsync详解之exclude排除文件【转】的相关文章

rsync详解之exclude排除文件

问题:如何避开同步指定的文件夹?  --excludersync  --exclude files and folders http://articles.slicehost.com/2007/10/10/rsync-exclude-files-and-folders 很常见的情况:我想同步/下的 /usr   /boot/ ,  但是不想复制/proc  /tmp 这些文件夹 如果想避开某个路径  直接添加--exclude 即可 比如--exclude "proc" --exclu

getClass()和getClassLoader()区别 以及ClassLoader详解及用途(文件加载,类加载)

获得ClassLoader的几种方法可以通过如下3种方法得到ClassLoader this.getClass().getClassLoader(); // 使用当前类的ClassLoader Thread.currentThread().getContextClassLoader(); // 使用当前线程的ClassLoader ClassLoader.getSystemClassLoader(); // 使用系统ClassLoader,即系统的入口点所使用的ClassLoader.(注意,s

详解Javac将java文件编译为class文件的过程

Java编译器总的来说分为前端编译器,JIT(just in time compiler)编译器,AOT(Ahead Of Time Compiler)编译器三种. 前端编译器: 将Java文件编译为class文件的编译器,目前主要有以下两个,Sun提供的Javac 和Eclipse JDT中的增量式编译器(ECJ) JIT编译器: 虚拟机后端运行期编译器,把字节码转换为机器码的过程.HotSpot Vm中提供的C1, C2编译器 AOT编译器:直接把Java文件转换为本地机器码的过程. GNU

【转】Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(下)

转载请注明出处:http://blog.csdn.net/qinjuning 上篇文章<<Android中measure过程.WRAP_CONTENT详解以及xml布局文件解析流程浅析(上)>>中,我们 了解了View树的转换过程以及如何设置View的LayoutParams的.本文继续沿着既定轨迹继续未完成的job. 主要知识点如下:                 1.MeasureSpc类说明                 2.measure过程详解(揭秘其细节);   

Dubbo+SpringMVC工程创建详解(附工程文件)

Dubbo+SpringMVC工程创建详解(附工程文件) Dubbo出现的目的是为了应对现在高并发,高数据量请求的问题.目前的垂直应用架构已经无法满足现在大数据的冲击,SOA就应运而生,而Dubbo在国内使用的还是比较多,稳定性也比较不错. 架构 节点角色说明: Provider: 暴露服务的服务提供方. Consumer: 调用远程服务的服务消费方. Registry: 服务注册与发现的注册中心. Monitor: 统计服务的调用次调和调用时间的监控中心. Container: 服务运行容器.

Rsync详解

一.拷贝操作 本地拷贝,相当cp [[email protected] ~]# rsync /etc/hosts /opt [[email protected] opt]# rsync -avz /etc/hosts /opt 保存属性一般参数 使用-v是进度,-z压缩传输-a归档模式 二.删除操作 [[email protected] ~]# rsync -r --delete /null/ /data/ rsync的删除操作,先建立一个空的目录null,然后把data目录下的文件删除.删除原

scp命令详解—跨服务器复制文件

scp在跨机器复制的时候为了提高数据的安全性,使用了ssh连接和加密方式,如果机器之间配置了ssh免密码登录,那在使用scp的时候密码都不用输入. 在服务器104.238.161.75上操作,将服务器104.238.161.75上/home/lk/目录下所有的文件全部复制到43.224.34.73的/root目录下,命令为:scp -r /home/lk [email protected]:/root(注意:IP与路径直接加冒号). 命令详解: scp是secure copy的简写,用于在Lin

pscp使用详解 Win与Linux文件互传工具

pscp使用方法详解: pscp是putty安装包所带的远程文件传输工具,是一款十分常见windows与linux系统之间文件互传的工具,使用方法与linux中的scp相似,这里来介绍一些详细的使用方法. PSCP下载地址:http://download.csdn.net/detail/doiido/8442599 版本:Release 0.60 语法: pscp [options] [[email protected]]host:source target pscp [options] sou

Android中measure过程、WRAP_CONTENT详解以及 xml布局文件解析流程浅析

转自:http://www.uml.org.cn/mobiledev/201211221.asp 今天,我着重讲解下如下三个内容: measure过程 WRAP_CONTENT.MATCH_PARENT/FILL_PARENT属性的原理说明 xml布局文件解析成View树的流程分析. 希望对大家能有帮助.- - 分析版本基于Android 2.3 . 1.WRAP_CONTENT.MATCH_PARENT/FILL_PARENT 初入Android殿堂的同学们,对这三个属性一定又爱又恨.爱的是使