Linux的rsync(一)

记录一下rsync命令的使用。
rsync意为remote sync,即远程同步的意思,它可以同步本地或远程机器上的文件或目录,其突出的特点为“增量同步”,这意味着它把变化的内容从源头同步到目的。

rsync语法:

同步方式语法
本地同步rsync {options} {source} {destination}
将远程内容同步至本地rsync {options} {User_name>@{Remote-Host}:{Source-File-Dir} {destination}
将本地内容同步至远程rsync {options} {source-file-dir} {User_name}@{Remote-Host}:{destination}

rsync后跟的一些常用选项

选项含义
-v, -verbose输出详细的信息
-q, -quiet抑制消息输出
-r, -recursive以递归的形式同步文件或目录
-z, -compress传输过程中压缩数据

rsync使用实例
1)、在本机同步文件
将当前目录下的a目录中的所有内容同步到当前目录的b目录下,使用如下的命令即可:

 rsync -zvh a/* b/

a.txt
sent 68 bytes  received 31 bytes  198.00 bytes/sec
total size is 2  speedup is 0.02

2)、本机递归同步
在递归同步时,可以使用-a或-r参数来实现,其中-a还能保留文件的元信息(修改时间、权限),因此命令如下:

 [root@hadoop102 ~]# rsync -zavh a/ainner b
sending incremental file list
ainner/
ainner/a.txt

sent 127 bytes  received 39 bytes  332.00 bytes/sec
total size is 5  speedup is 0.03
 或者
 [root@hadoop102 ~]# rsync -zrvh a/ainner b
sending incremental file list
ainner/
ainner/a.txt

sent 125 bytes  received 39 bytes  328.00 bytes/sec
total size is 5  speedup is 0.03

3)、将文件或目录从本地同步到远程机器

[root@hadoop102 ~]# rsync  -zavh a/ainner root@192.168.1.17:/root/b
The authenticity of host '192.168.1.17 (192.168.1.17)' can't be established.
ECDSA key fingerprint is SHA256:19DdNuhGPyPdcLx8za4M/g+cZ6SFrSk6WHpAuA5S8/0.
ECDSA key fingerprint is MD5:c9:c3:ee:2d:80:01:2d:d3:90:20:e4:31:af:22:20:d9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.17' (ECDSA) to the list of known hosts.
root@192.168.1.17's password:
sending incremental file list
ainner/
ainner/a.txt

sent 127 bytes  received 39 bytes  30.18 bytes/sec
total size is 5  speedup is 0.03

4)、将文件或目录从远程同步到本机

[root@hadoop102 ~]# rsync -zavh root@192.168.1.17:/root/b b/
root@192.168.1.17's password:
receiving incremental file list
b/
b/ainner/
b/ainner/a.txt

sent 55 bytes  received 152 bytes  37.64 bytes/sec
total size is 5  speedup is 0.02
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值