Linux下面rsync 实现 完全一致的同步方法
1. 在某些特殊的linux机器上面, 比如龙芯后者是飞腾服务器,部分工具不太好用, 需要使用x86弄好之后进行同步过去, 这个时候scp 最简单但是网络流量非常大, 不如使用rsync, rsync 一开始不知道能够实现source文件夹的删除操作, destation文件夹也可以重演.
2. rsync的两种模式
ssh模式和daemon模式.
简单起见 可以使用ssh-copy-id 实现无密码登录的话 可以使用 ssh 模式 更加方便一些.
关于rsync的两种模式:
该部分额外的内容来自IBM官方网站上的一篇文章。该文章把rsync的运行模式扩展成了四种,但我认为rsync官方文档的两种模式的划分更加合理一些。
所谓rsync daemon,就是在一台机器上永久运行的rsync进程。在任何一台安装rsync的机器上运行rsync --daemon,则这台机器上运行的rsync就是rsync daemon。我们可以把文件发送给daemon,也可以向daemon请求文件。
daemon模式非常适合创建中心备份服务器,或项目存储库。
两种模式的区别前面已经说过,shell模式在源路径和目的路径中使用一个冒号,而daemon模式使用两个冒号。 关于rsync命令的语法:
本地拷贝:
rsync [选项] SRC… DEST,在本地进行复制操作 shell模式:
rsync [选项] [user@]Host:SRC… [DEST],拉动作,从远程主机拉文件到本地
rsync [选项] SRC… [user@]Host:DEST,推动作,把本地文件推送到远程主机 daemon模式:
rsync [选项] [user@]Host::SRC… [DEST],拉动作
rsync [选项] rsync://[user@]Host [:port]/SRC… [DEST],仍然是拉动作
rsync [选项] SRC... [user@]Host::DEST,推动作
rsync [选项] SRC...rsync://[user@]Host [:port]/DEST,仍然是推动作
来源: https://blog.csdn.net/s1070/article/details/77978907
3. 简单测试验证:
host01 mkdir /zhaobsh
touch a b c d e host02 mkdir /zhaobsh
touch b c d e f
然后在源文件的host01 机器上面执行命令
rsync -azc . root@10.24.20.201:/zhaobsh/

host02 机器 执行命令之前的文件为:

执行命令之后的文件为:

4. 如果想验证能够删除 source 里面不存在的文件 那么需要添加参数
rsync -azc . --delete root@10.24.20.201:/zhaobsh/
就会发现 source 里面没有的文件 f 就会在destination

5. 其实GNU工具链非常好 里面的东西非常实用 直接看help的话 就能学到很多东西(就是自己的耐心不够)
[root@centos76 zhaobsh]# rsync --help
rsync version 3.1.2 protocol version 31
Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
append, ACLs, xattrs, iconv, symtimes, prealloc rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. See the GNU
General Public Licence for details. rsync is a file transfer program capable of efficient remote update
via a fast differencing algorithm. Usage: rsync [OPTION]... SRC [SRC]... DEST
or rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
or rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
or rsync [OPTION]... [USER@]HOST:SRC [DEST]
or rsync [OPTION]... [USER@]HOST::SRC [DEST]
or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
The ':' usages connect via remote shell, while '::' & 'rsync://' usages connect
to an rsync daemon, and require SRC or DEST to start with a module name. Options
-v, --verbose increase verbosity
--info=FLAGS fine-grained informational verbosity
--debug=FLAGS fine-grained debug verbosity
--msgs2stderr special output handling for debugging
-q, --quiet suppress non-error messages
--no-motd suppress daemon-mode MOTD (see manpage caveat)
-c, --checksum skip based on checksum, not mod-time & size
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
--no-OPTION turn off an implied OPTION (e.g. --no-D)
-r, --recursive recurse into directories
-R, --relative use relative path names
--no-implied-dirs don't send implied dirs with --relative
-b, --backup make backups (see --suffix & --backup-dir)
--backup-dir=DIR make backups into hierarchy based in DIR
--suffix=SUFFIX set backup suffix (default ~ w/o --backup-dir)
-u, --update skip files that are newer on the receiver
--inplace update destination files in-place (SEE MAN PAGE)
--append append data onto shorter files
--append-verify like --append, but with old data in file checksum
-d, --dirs transfer directories without recursing
-l, --links copy symlinks as symlinks
-L, --copy-links transform symlink into referent file/dir
--copy-unsafe-links only "unsafe" symlinks are transformed
--safe-links ignore symlinks that point outside the source tree
--munge-links munge symlinks to make them safer (but unusable)
-k, --copy-dirlinks transform symlink to a dir into referent dir
-K, --keep-dirlinks treat symlinked dir on receiver as dir
-H, --hard-links preserve hard links
-p, --perms preserve permissions
-E, --executability preserve the file's executability
--chmod=CHMOD affect file and/or directory permissions
-A, --acls preserve ACLs (implies --perms)
-X, --xattrs preserve extended attributes
-o, --owner preserve owner (super-user only)
-g, --group preserve group
--devices preserve device files (super-user only)
--copy-devices copy device contents as regular file
--specials preserve special files
-D same as --devices --specials
-t, --times preserve modification times
-O, --omit-dir-times omit directories from --times
-J, --omit-link-times omit symlinks from --times
--super receiver attempts super-user activities
--fake-super store/recover privileged attrs using xattrs
-S, --sparse handle sparse files efficiently
--preallocate allocate dest files before writing them
-n, --dry-run perform a trial run with no changes made
-W, --whole-file copy files whole (without delta-xfer algorithm)
-x, --one-file-system don't cross filesystem boundaries
-B, --block-size=SIZE force a fixed checksum block-size
-e, --rsh=COMMAND specify the remote shell to use
--rsync-path=PROGRAM specify the rsync to run on the remote machine
--existing skip creating new files on receiver
--ignore-existing skip updating files that already exist on receiver
--remove-source-files sender removes synchronized files (non-dirs)
--del an alias for --delete-during
--delete delete extraneous files from destination dirs
--delete-before receiver deletes before transfer, not during
--delete-during receiver deletes during the transfer
--delete-delay find deletions during, delete after
--delete-after receiver deletes after transfer, not during
--delete-excluded also delete excluded files from destination dirs
--ignore-missing-args ignore missing source args without error
--delete-missing-args delete missing source args from destination
--ignore-errors delete even if there are I/O errors
--force force deletion of directories even if not empty
--max-delete=NUM don't delete more than NUM files
--max-size=SIZE don't transfer any file larger than SIZE
--min-size=SIZE don't transfer any file smaller than SIZE
--partial keep partially transferred files
--partial-dir=DIR put a partially transferred file into DIR
--delay-updates put all updated files into place at transfer's end
-m, --prune-empty-dirs prune empty directory chains from the file-list
--numeric-ids don't map uid/gid values by user/group name
--usermap=STRING custom username mapping
--groupmap=STRING custom groupname mapping
--chown=USER:GROUP simple username/groupname mapping
--timeout=SECONDS set I/O timeout in seconds
--contimeout=SECONDS set daemon connection timeout in seconds
-I, --ignore-times don't skip files that match in size and mod-time
-M, --remote-option=OPTION send OPTION to the remote side only
--size-only skip files that match in size
--modify-window=NUM compare mod-times with reduced accuracy
-T, --temp-dir=DIR create temporary files in directory DIR
-y, --fuzzy find similar file for basis if no dest file
--compare-dest=DIR also compare destination files relative to DIR
--copy-dest=DIR ... and include copies of unchanged files
--link-dest=DIR hardlink to files in DIR when unchanged
-z, --compress compress file data during the transfer
--compress-level=NUM explicitly set compression level
--skip-compress=LIST skip compressing files with a suffix in LIST
-C, --cvs-exclude auto-ignore files the same way CVS does
-f, --filter=RULE add a file-filtering RULE
-F same as --filter='dir-merge /.rsync-filter'
repeated: --filter='- .rsync-filter'
--exclude=PATTERN exclude files matching PATTERN
--exclude-from=FILE read exclude patterns from FILE
--include=PATTERN don't exclude files matching PATTERN
--include-from=FILE read include patterns from FILE
--files-from=FILE read list of source-file names from FILE
-0, --from0 all *-from/filter files are delimited by 0s
-s, --protect-args no space-splitting; only wildcard special-chars
--address=ADDRESS bind address for outgoing socket to daemon
--port=PORT specify double-colon alternate port number
--sockopts=OPTIONS specify custom TCP options
--blocking-io use blocking I/O for the remote shell
--stats give some file-transfer stats
-8, --8-bit-output leave high-bit chars unescaped in output
-h, --human-readable output numbers in a human-readable format
--progress show progress during transfer
-P same as --partial --progress
-i, --itemize-changes output a change-summary for all updates
--out-format=FORMAT output updates using the specified FORMAT
--log-file=FILE log what we're doing to the specified FILE
--log-file-format=FMT log updates using the specified FMT
--password-file=FILE read daemon-access password from FILE
--list-only list the files instead of copying them
--bwlimit=RATE limit socket I/O bandwidth
--outbuf=N|L|B set output buffering to None, Line, or Block
--write-batch=FILE write a batched update to FILE
--only-write-batch=FILE like --write-batch but w/o updating destination
--read-batch=FILE read a batched update from FILE
--protocol=NUM force an older protocol version to be used
--iconv=CONVERT_SPEC request charset conversion of filenames
--checksum-seed=NUM set block/file checksum seed (advanced)
-4, --ipv4 prefer IPv4
-6, --ipv6 prefer IPv6
--version print version number
(-h) --help show this help (-h is --help only if used alone) Use "rsync --daemon --help" to see the daemon-mode command-line options.
Please see the rsync(1) and rsyncd.conf(5) man pages for full documentation.
See http://rsync.samba.org/ for updates, bug reports, and answers
Linux下面rsync 实现 完全一致的同步方法的更多相关文章
- Windows Linux 之间rsync同步CODE文件
Windows Linux 之间rsync同步CODE文件 一.环境Windows:OS:Microsoft Windows Web Server 2008 SP1IP:192.168.88.197 ...
- Linux下Rsync+sersync实现数据实时同步
inotify 的同步备份机制有着缺点,于是看了sersync同步,弥补了rsync的缺点.以下转自:http://www.osyunwei.com/archives/7447.html 前言: 一. ...
- linux下rsync和tar增量备份梳理
前面总结过一篇全量备份/增量备份/差异备份说明,下面介绍下linux下rsync和tar两种增量备份的操作记录: 1)rsync备份 rsync由于本身的特性,在第一次rsync备份后,以后每次都只是 ...
- Linux下Rsync+Inotify-tools实现数据实时同步
Linux下Rsync+Inotify-tools实现数据实时同步 注意:下面的三个案例都是rsync 每次都是全量的同步(这就坑爹了),而且 file列表是循环形式触发rsync ,等于有10个文件 ...
- linux设置rsync+inotify实时同步文件
linux设置rsync+inotify实时同步文件 应用场景: 同步接收方:test01 接收目录:/opt/software/test/a/ 同步发起方:test02 同步目录:/opt/so ...
- Linux服务-rsync
目录 1. rsync简介 2. rsync特性 3. rsync的ssh认证协议 4. rsync命令 5. rsync+inotify Linux服务-rsync 1. rsync简介 rsync ...
- linux中rsync备份文件
linux中rsync备份文件 备份文件的方式 备份方式: cp : 本机复制 scp: 远程复制 推(本地上传到远程服务器): scp 1.txt root@ip:[路径] [root@m01 ~] ...
- Linux 安装Rsync和配置
1.检查rsync 是否已经安装 [root@test home]# rpm -qa|grep rsync 若已经安装,则使用rpm -e 命令卸载. [root@test home]#rpm -e ...
- 【Linux】rsync同步文件 & 程序自启动
rsync使用 1. 为什么使用rsync? rsync解决linux系统下文件同步时, 增量同步问题. 使用场景: 线上需要定时备份数据文件(视频资源), 使用rsync完成每天的增量备份. 参见: ...
- Rsync(远程同步): linux中Rsync命令的实际示例
rsync的 ( 远程同步 )为在Linux / Unix系统局部 拷贝和同步文件和目录远程以及一个最常用的命令. 随着rsync命令的帮助,您可以复制并在目录中远程和本地同步数据,在磁盘和网络,进行 ...
随机推荐
- ECS实践案例丨逻辑卷的创建和扩容操作指导
摘要:实现跨硬盘使用,在传统硬盘之上的一层,在云服务器中可以实现跨EVS使用,用户在某些场景需要创建逻辑卷或者对已有的逻辑卷进行扩容处理,或者在某些时候由于误操作导致上述操作失败. [背景描述]: 实 ...
- 从原理到实践,手把手带你轻松get数仓双集群容灾
摘要:本文通过介绍双集群的架构.log结构.分析步骤来介绍双集群容灾的问题分析方法. 本文分享自华为云社区<从原理到实践,手把手带你轻松get数仓双集群容灾>,原文作者:Puyol . 双 ...
- 📝 App备案与iOS云管理式证书 ,公钥及证书SHA-1指纹的获取方法
引言 在iOS应用程序开发过程中,进行App备案并获取公钥及证书SHA-1指纹是至关重要的步骤.本文将介绍如何通过appuploader工具获取iOS云管理式证书 Distribution Man ...
- 火山引擎DataLeap:助你实现从数据研发1.0到数据研发3.0的跨越
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 近日,火山引擎开发者社区 Meetup 第 12 期暨超话数据专场在深圳举办,本次活动主题为"数智化转型 ...
- Solon 项目的单元测试插件
1.引入依赖 <dependency> <groupId>org.noear</groupId> <artifactId>solon-test</ ...
- Python网络编程:ZeroMQ
大家好,我是老胡.最近在和小伙伴们一起搞事情,我是学统计出身,编程能力其实很差,有点拖后腿了.所以需要恶补基础,这个系列会更新几篇,感兴趣的同学可以一起学习交流. ZeroMQ概述 ZeroMQ(又名 ...
- 深入浅出 WebRTC AEC(声学回声消除)
前言:近年来,音视频会议产品提升着工作协同的效率,在线教育产品突破着传统教育形式的种种限制,娱乐互动直播产品丰富着生活社交的多样性,背后都离不开音视频通信技术的优化与创新,其中音频信息内容传递的流畅性 ...
- 透析阿里云视频云「低代码音视频工厂」之能量引擎——vPaaS 视频原生应用开发平台
为满足企业用户极速搭建高品质专属音视频业务的需求,阿里云视频云的"低代码音视频工厂"应运而生,但极速而高品质的平台搭建诉求,需要用全新的开发方式才能真正实现,而全新的开发方式背后蕴 ...
- 【驱动】以太网扫盲(三)PHY的控制器驱动框架分析
1. 概述 PHY芯片为OSI的最底层-物理层(Physical Layer),通过MII/GMII/RMII/SGMII/XGMII等多种媒体独立接口(介质无关接口)与数据链路层的MAC芯片相连,并 ...
- map三层循环遍历,操作数据
let tempArr = this.oldCityList.map(item => { return { value: item.code, text: item.name, type: it ...