rsync命令比对文件及增量同步

rsync - a fast, versatile, remote (and local) file-copying tool.
Rsync finds files that need to be transferred using a "quick check" algorithm (by default) that looks for files that have changed in size or in last-modified time.
Usages with just one SRC arg and no DEST arg will list the source files instead of copying.

常见用法

Pull: rsync user@host:SRC [DEST]    将远程文件复制到本地
Push: rsync SRC user@host:DEST    将本地文件复制到远端

常用选项

-q,--quiet: suppress non-error messages 静默模式
-v,--verbose: increase verbosity
-a,--archive: archive mode; equals -rlptgoD (no -H,-A,-X) 归档模式,相当于-rlptgoD,不包括(no -H,-A,-X)。最常用的参数
-H,--hard-links: preserve hard links 保留硬链接
-A,--acls: preserve ACLs (implies --perms) 保留ACL权限
-X,--xattrs: preserve extended attributes 保留扩展属性
-c, --checksum: skip based on checksum, not mod-time & size
-r,--recursive: recurse into directories 递归
-l,--links: copy symlinks as symlinks 保留软链接,而不跟踪原文件
-p,--perms: preserve permissions 保留权限
-t,--times: preserve modification times 保留mtime
-g,--group: preserve group 保留属组
-o,--owner: preserve owner (super-user only) 保留属主
-D: same as --devices,--specials 保留设备文件和特殊文件
--devices: preserve device files (super-user only)
--specials: preserve special files
--bwlimit=RATE: limit socket I/O bandwidth

-z,--compress: compress file data during the transfer 传输过程中压缩文件数据
-n, --dry-run: perform a trial run with no changes made 干跑测试
-u,--update: skip files that are newer on the receiver 跳过接收端更加新的文件
--delete: delete extraneous files from destination dirs 删除接收端多出来的文件
--partial: keep partially transferred files 保留部分传输的文件
--progress: show progress during transfer 显示传输进度
-P: The -P option is equivalent to --partial --progress

--exclude=PATTERN: exclude files matching PATTERN 通配符
--include=PATTERN: don't exclude files matching PATTERN 通配符

本地复制

rsync -av ansible_auto/public/ objects/ansible_auto/public/

比对文件

cd /usr/local/nagios/etc/
rsync -avcn ansible_auto/ objects/ansible_auto/ > diff

增量同步(合并目录文件)

rsync -avzuP /opt/ root@11.0.10.8:/opt/

同步并删除(删除目标目录多余文件,最终与源目录一致)

rsync -avzuP --delete /opt/ root@11.0.10.8:/opt/

参考文档

posted @ 2017-08-06 05:41  KeithTt  阅读(13659)  评论(0编辑  收藏  举报