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 实现 完全一致的同步方法的更多相关文章

  1. Windows Linux 之间rsync同步CODE文件

    Windows Linux 之间rsync同步CODE文件 一.环境Windows:OS:Microsoft Windows Web Server 2008 SP1IP:192.168.88.197 ...

  2. Linux下Rsync+sersync实现数据实时同步

    inotify 的同步备份机制有着缺点,于是看了sersync同步,弥补了rsync的缺点.以下转自:http://www.osyunwei.com/archives/7447.html 前言: 一. ...

  3. linux下rsync和tar增量备份梳理

    前面总结过一篇全量备份/增量备份/差异备份说明,下面介绍下linux下rsync和tar两种增量备份的操作记录: 1)rsync备份 rsync由于本身的特性,在第一次rsync备份后,以后每次都只是 ...

  4. Linux下Rsync+Inotify-tools实现数据实时同步

    Linux下Rsync+Inotify-tools实现数据实时同步 注意:下面的三个案例都是rsync 每次都是全量的同步(这就坑爹了),而且 file列表是循环形式触发rsync ,等于有10个文件 ...

  5. linux设置rsync+inotify实时同步文件

    linux设置rsync+inotify实时同步文件   应用场景: 同步接收方:test01 接收目录:/opt/software/test/a/ 同步发起方:test02 同步目录:/opt/so ...

  6. Linux服务-rsync

    目录 1. rsync简介 2. rsync特性 3. rsync的ssh认证协议 4. rsync命令 5. rsync+inotify Linux服务-rsync 1. rsync简介 rsync ...

  7. linux中rsync备份文件

    linux中rsync备份文件 备份文件的方式 备份方式: cp : 本机复制 scp: 远程复制 推(本地上传到远程服务器): scp 1.txt root@ip:[路径] [root@m01 ~] ...

  8. Linux 安装Rsync和配置

    1.检查rsync 是否已经安装 [root@test home]# rpm -qa|grep rsync 若已经安装,则使用rpm -e 命令卸载. [root@test home]#rpm -e ...

  9. 【Linux】rsync同步文件 & 程序自启动

    rsync使用 1. 为什么使用rsync? rsync解决linux系统下文件同步时, 增量同步问题. 使用场景: 线上需要定时备份数据文件(视频资源), 使用rsync完成每天的增量备份. 参见: ...

  10. Rsync(远程同步): linux中Rsync命令的实际示例

    rsync的 ( 远程同步 )为在Linux / Unix系统局部 拷贝和同步文件和目录远程以及一个最常用的命令. 随着rsync命令的帮助,您可以复制并在目录中远程和本地同步数据,在磁盘和网络,进行 ...

随机推荐

  1. JVM面试必问:G1垃圾回收器

    摘要:G1垃圾回收器是一款主要面向服务端应用的垃圾收集器. 本文分享自华为云社区<JVM面试高频考点:由浅入深带你了解G1垃圾回收器!!!>,原文作者:Code皮皮虾 . G1垃圾回收器介 ...

  2. Hudi Bucket Index 在字节跳动的设计与实践

    由字节跳动数据湖团队贡献的 RFC-29 Bucket Index 在近期合入 Hudi 主分支,本文详细介绍 Hudi Bucket Index 产生的背景与实践经验.字节跳动数据湖团队持续招人中, ...

  3. kubernetes实战(三十一):Prometheus监控Windows主机

    1. 基本说明 使用Prometheus监控Windows主机和Linux主机并无太大区别,都是使用社区的Exporter进行采集数据,之后暴露一个接口,可以让Prometheus采集到主机的数据. ...

  4. Chrome 护眼模式 - 黑暗模式 - 夜眼(Night Eye) 插件

    Chrome 地址栏里输入: chrome://extensions/ 打开插件商城:

  5. MVCC多版本并发控制和幻读问题的解决

    首先我们先介绍一下锁的分类,再进入今天的正题. 一.锁分类: 1.从性能上分:乐观锁.悲观锁.乐观锁(用版本号对比或CAS机制)适用于读比较多的场景,悲观锁适用于写比较多的场景.如果在写比较多的场景使 ...

  6. 灵魂拷问std::enable_shared_from_this,揭秘实现原理

    参考博客: std::enable_shared_from_this原理浅析 引言 在C++编程中,使用智能指针是一种安全管理对象生命周期的方式.std::shared_ptr是一种允许多个指针共享对 ...

  7. L1-046 整除光棍 (20分)

    问题描述 这里所谓的"光棍",并不是指单身汪啦~ 说的是全部由1组成的数字,比如1.11.111.1111等.传说任何一个光棍都能被一个不以5结尾的奇数整除.比如,111111就可 ...

  8. Codeforce 515C. Drazil and Factorial(字符串思维题)

    [CodeForces]C. Drazil and Factorial 题目链接:Click Here 题意:找一个最大的数,使得每个位的阶乘的乘积与给定数相同. 首先將 2~9 轉成這樣(0,1為空 ...

  9. 项目2 可视化数据(第17章 使用API)

    17.1 使用Web API Web API是网站的一部分,用于与使用非常具体的URL请求特定信息的程序交互.这种请求称为API调用.请求的数据将以易于处理的格式(如JSON或CSV)返回. 17.1 ...

  10. L2-029 特立独行的幸福 (25分) (简单循环 + 素数筛)

    对一个十进制数的各位数字做一次平方和,称作一次迭代.如果一个十进制数能通过若干次迭代得到 1,就称该数为幸福数.1 是一个幸福数.此外,例如 19 经过 1 次迭代得到 82,2 次迭代后得到 68, ...