Linux操作系统中rsync工具常见用法_linux中rsync使用账密形式socks代理(1)

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

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:DEST

Access via rsync daemon:
Pull: rsync [OPTION…] [USER@]HOST::SRC… [DEST]
rsync [OPTION…] rsync://[USER@]HOST[:PORT]/SRC… [DEST]
Push: rsync [OPTION…] SRC… [USER@]HOST::DEST
rsync [OPTION…] SRC… rsync://[USER@]HOST[:PORT]/DEST

Usages with just one SRC arg and no DEST arg will list the source files instead of copying.


### 3.2 命令选项介绍


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



-e, --rsh=COMMAND
This 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, --archive
This 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, --verbose
This 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, --compress
With 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/

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 11
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值