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命令的帮助,您可以复制并在目录中远程和本地同步数据,在磁盘和网络,进行 ...
随机推荐
- 数据交换不失控:华为云EDS,让你的数据你做主
摘要:华为云EDS在"可信.可控.可证"的框架基础上进行数据空间的关键设计,打造数据可控交换的全栈能力. 数字社会,每时每刻都有海量数据产生,数据也逐渐从生产过程的附属产物,逐渐成 ...
- 手把手带你入门加密算法的Python实现
摘要:一个简单的md5加密算法,带你解开所谓"加密"过程的神秘面纱. 一个简单的md5加密算法,非常适合新手练习 链接:> aHR0cDovL3d3dy5jaHVjaHVqa ...
- 一键自动修改和翻新OC源码,解决苹果审核4.3和马甲问题
ipaguard 自动修改/翻新/混淆/OC/iOS代码,自动替换类名,方法名 由来 网上有很多关于如何混淆iOS源码的方法,但是都不够智能,生成的方法类名要么千奇百怪,要么aaaabbbxxx这 ...
- IOS上架流程详解,包含审核避坑指南!
准备 开发者账号 完工的项目 上架步骤 一.创建App ID 二.创建证书请求文件 (CSR文件) 三.创建发布证书 (CER) 四.创建Provisioning Profiles配置文件 (PP ...
- 火山引擎 DataTester:A/B 实验如何实现人群智能化定向?
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 在精细化运营时代,用户需求和业务场景愈加多元,在产品功能迭代以及各类活动中,面向不同人群的兴趣点,有针对性地&qu ...
- Kubernetes(K8S) 配置管理 Secret 介绍
Secret 作用:加密数据(base64)存在 etcd 里面,让 Pod 容器以挂载 Volume 方式进行访问 场景:凭证 [root@k8smaster ~]# echo -n 'admin' ...
- JupyterLab 这插件太强了,Excel灵魂附体
终于把 jupyter notebook 玩明白了 JupyterLab 终于出了 Windows 桌面版 今天向大家介绍一款很有意思的 JupyterLab 插件 -- Mito Mito是Jupy ...
- 【redis】 redis linux下安装 redis启动方式 redis典型场景 redis通用命令 数据结构和内部编码 redis字符串类型
目录 上节回顾 今日内容 1 redis介绍 2 redis linux下安装 3 redis启动方式 3.1 最简启动 3.2 动态参数启动 3.3 配置文件启动 3.4 客户端连接命令 4 red ...
- SAP搜索帮助的限制值范围样式
样式一: 点击下拉框,输入筛选数据,筛选搜索帮助列表 样式二: 点击漏斗,输入筛选数据,筛选搜索帮助列表 参数设置: 不同的样式,通过账号的参数设置决定 第一种样式:没有配置F4METHOD,或者配置 ...
- 浅谈 Java 中的 AutoCloseable 接口
本文对 try-with-resources 语法进行了较为深入的剖析,验证了其为一种语法糖,同时给出了其实际的实现方式的反编译结果,相信你在看完本文后,关于 AutoCloseable 的使用你会有 ...