本文主要介绍 Linux 操作系统中 rsync 工具的常见用法。

1 概述

1.1 What

此处引用 Manual 手册中对 rsync 的介绍,内容如下:

rsync - a fast, versatile, remote (and local) file-copying tool.

Rsync  is  a  fast and extraordinarily versatile file copying tool.  It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon.  It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied.  It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

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.  Any changes in the other preserved attributes (as requested by options) are made on the destination file directly when the quick check indicates that the file’s data does not need to be updated.

2 安装

可以通过 yum 命令直接安装 rsync 工具。命令如下:

yum install rsync.x86_64

3 用法

3.1 语法介绍

rsync 传输文件的方式有三种:本地传输、通过远端 shell 传输、通过 rsync 守护进程传输。

三种传输方式的语法信息如下:

Local:  rsync [OPTION...] SRC... [DEST]Access via remote shell:Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]Push: rsync [OPTION...] SRC... [USER@]HOST:DESTAccess via rsync daemon:Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]Push: rsync [OPTION...] SRC... [USER@]HOST::DESTrsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DESTUsages with just one SRC arg and no DEST arg will list the source files instead of copying.

3.2 命令选项介绍

-e 选项(设置用于文件传输的远端 shell 程序):

-e, --rsh=COMMANDThis option allows you to choose an alternative remote shell program to use for
communication between the local and remote copies of rsync. Typically, rsync is configured
to use ssh by default, but you may prefer to use rsh on a local network.

-a 选项(归档模式):

-a, --archiveThis is equivalent to -rlptgoD. It is a quick way of saying you want recursion and
want to preserve almost everything (with -H being a notable omission). The only exception
to the above equivalence is when --files-from is specified, in which case -r is not
implied.Note that -a does not preserve hardlinks, because finding multiply-linked files is
expensive. You must separately specify -H.

-v 选项(详情显示):

-v, --verboseThis option increases the amount of information the daemon logs during its startup
phase. After the client connects, the daemon’s verbosity level will be controlled by the
options that the client used and the "max verbosity" setting in the module’s config section.

-z 选项(压缩模式):

-z, --compressWith this option, rsync compresses the file data as it is sent to the destination
machine, which reduces the amount of data being transmitted -- something that is useful
over a slow connection.

-P 选项(传输中断后保留已传输文件):

-P     The -P option is equivalent to --partial --progress.  Its purpose is to make it much
easier to specify these two options for a long transfer that may be interrupted.

3.3 用法示例

3.3.1 使用远端ssh程序传输文件

使用远端 (remote-shell)ssh 程序,将本地 /opt/liitdar/mydemos/ 目录下的 simples 文件夹以及其中的文件传输到远端主机(192.168.213.130)的 /opt/liitdar/mydemos/ 目录下,命令如下:

[root@node1 /opt/liitdar/mydemos]# rsync simples -avzP -e 'ssh -p 22' root@192.168.213.130:/opt/liitdar/mydemos/

说明:使用 ssh 程序传输文件时,需要输入对端的用户密码。

3.3.2 测试修改文件后的同步功能

承接“3.3.1”节操作,现在修改远端主机 (192.168.213.130)的 /opt/liitdar/mydemos/simples 目录下的 semicolon_test1.cpp 文件的内容,然后再使用上一步的 rsync 命令进行文件传输(同步),此时可以看到如下信息:

[root@node1 /opt/liitdar/mydemos]# rsync simples -avzP -e 'ssh -p 22' root@192.168.213.130:/opt/liitdar/mydemos/
root@192.168.213.130's password:
sending incremental file list
simples/
simples/semicolon_test1.cpp235 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=7/12)sent 441 bytes  received 46 bytes  51.26 bytes/sec
total size is 110,344  speedup is 226.58
[root@node1 /opt/liitdar/mydemos]#

通过上述传输信息可知,rsync 只将(本地与远端之间)存在差异的文件(semicolon_test1.cpp)传输(同步)到了远端,这是 rsync 工具的一个主要特点(优点)。

Linux操作系统中rsync工具常见用法相关推荐

  1. Linux操作系统中man命令的用法,Linux 系统中的MAN命令使用祥解

    Linux 系统中的MAN命令使用祥解 在使用Linux命令或程序的过程中,大家免不了要看看命令和程序的帮助文档.这就要使用到man命令.下面就man命令使用的方法具体说一下: 1.man 的使用语法 ...

  2. Linux中head和tail命令作用,Linux 命令head和tail常见用法详解

    head和tail是一组想对应的命令,默认分别显示文件的开头和末尾10行记录. head head 命令可以将一段文本的开头一部分输出到标准输出. head命令既可以处理文本文件也可以处理标准输入. ...

  3. Linux操作系统中的make及makefile介绍

    本文主要介绍 Linux 操作系统中 make 及 makefile 的相关知识. 1 What make 是一个在软件开发过程中所使用的工具程序(utility software),通过读取&quo ...

  4. 在linux系统中进行路由探测,如何在Linux操作系统中运行Traceroute命令?

    Traceroute是Linux操作系统中的命令工具,可用于查看网络数据包的路由.Traceroute可以帮助确定网络数据包传输的质量好坏,同时对于排除缓慢的网络连接故障也很有用. 在租用 关于Tra ...

  5. Linux操作系统中Anaconda的安装

    Linux操作系统中anaconda的安装 Anaconda由数据科学家为数据科学家建造,超过2000万人使用我们的技术来解决最棘手的问题. Anaconda其实就是一个开源的Python发行版本,其 ...

  6. 在 Linux 操作系统中安装 Java

    在 Linux 操作系统中安装 Java 笔者的运行环境: CentOS Stream 8 x86_64 Java 11.0.12 进行这个教程之前,必须要先安装好一个 Linux 操作系统.这个 L ...

  7. 【转】聊聊Linux操作系统中的显示管理器及如何更换

    转自:聊聊Linux操作系统中的显示管理器及如何更换 - linux-123 - 博客园 聊聊Linux操作系统中的显示管理器及如何更换 | <Linux就该这么学> 什么是 Linux ...

  8. linux系统中ssh命令,Linux系统中SSH 命令的用法有哪些?

    今天小编要跟大家分享的文章是关于Linux系统中SSH命令的用法有哪些?一个系统管理员可能会同时管理着多台服务器,这些服务器也许会放在不同的地方.要亲自一台一台的去访问来管理它们显然不是最好的方法,通 ...

  9. linux日志配置含义,Linux操作系统中的日志功能详解

    日志系统将我们系统运行的每一个状况信息都使用文字记录下来,这些信息有助我们观察系统运行过程中正常状态和系统运行错误时快速定位错误位置的途径等;下面学习啦小编主要概述一下Linux操作系统中的日志功能. ...

  10. php执行md5sum,Linux_详解Linux系统中md5sum命令的用法,MD5算法常常被用来验证网络文 - phpStudy...

    详解Linux系统中md5sum命令的用法 MD5算法常常被用来验证网络文件传输的完整性,防止文件被人篡改.MD5全称是报文摘要算法(Message-Digest Algorithm 5),此算法对任 ...

最新文章

  1. Matlab随笔之矩阵入门知识
  2. 「SAP技术」交货单发货过账报错 - Material's product unit must be entered in whole numbers - 之对策
  3. python---4
  4. HTTPS协议原理分析
  5. WP7技巧 扩展【共享...】按钮
  6. php栏目树,php生成无限栏目树的代码实例分享
  7. linux 与window 相互共享命令
  8. Wi-Fi 6 认证计划启动:开启 Wi-Fi 新纪元
  9. 学 Python 没找对路到底有多惨?| 码书
  10. 数据库原理mysql_数据库原理:MySql的安装
  11. FISCO BCOS(九)——— WeBase的节点前置服务
  12. python水仙花数的代码_Python水仙花数的编程代码写法
  13. 网上找的视频素材有水印怎么办?教你一键打码
  14. 乐高wedo2.0电脑软件安装及蓝牙连接方法
  15. 微信指纹支付原理浅析
  16. 老徐WEB:js入门学习 - javascript对象之Date对象
  17. 鸿蒙开发工具在哪下载,【鸿蒙开发工具下载】华为鸿蒙开发工具软件下载 v2.1.8 最新版-七喜软件园...
  18. offline translator android app,PROMT Offline Translator English Pack
  19. 输入一个字符,将大写字母换小写,小写变大写
  20. 通证大局观(二):通证权益解析

热门文章

  1. 深度学习中拟合是什么意思?
  2. unity中简单的血条自作
  3. [10秒学会] - iOS录制屏幕 ReplayKit
  4. ThinkPhp学习01
  5. Xbox One 游戏欣赏: 麦克斯-兄弟魔咒
  6. C++的性能C#的产能?! - .Net Native 系列向导
  7. 编译并运行Java文件
  8. 第一个servlet
  9. 【图文详解】用Eclipse创建Maven Web项目
  10. Linq简单语句记录