rsync数据同步和 ssh+rsync

Rsync概述Remote sync 远程同步支持本地复制 或与其他ssh rsync主机同步官方网站: http://rsync.samba.org/Rsync同步操作命令用法Rsync [选项。。] 源目录 目标目录同步与复制的差异复制:完全拷贝源到目标同步:增量拷贝 只传输变化的数据本地同步Rsync [选项。。] 本地目录1 本地目录2 Rsync [选项。。] 本地目录1 本地目录 2rsync同步工具的常用选项:-n:测试同...
摘要由CSDN通过智能技术生成

Rsync概述

 Remote sync 远程同步

支持本地复制 或与其他ssh  rsync主机同步

官方网站: http://rsync.samba.org/

Rsync同步操作

命令用法

Rsync [选项。。] 源目录  目标目录

同步与复制的差异

复制:完全拷贝源到目标

同步:增量拷贝 只传输变化的数据

 

本地同步

Rsync [选项。。] 本地目录1 本地目录2  

Rsync [选项。。]  本地目录1 本地目录 2

rsync同步工具的常用选项:

  • -n:测试同步过程,不做实际修改
  • --delete:删除目标文件夹内多余的文档
  • -a:归档模式,相当于-rlptgoD
  • -v:显示详细操作信息
  • -z:传输过程中启用压缩/解压

步骤一:rsync同步基本操作

1)将目录 /boot 同步到目录 /todir 下

copytextpop-up

  1. [root@svr7 ~]# ls  -l  /todir                  //同步前
  2. ls: 无法访问/todir: 没有那个文件或目录
  3. [root@svr7 ~]# rsync  -a  /boot  /todir          //将目录1作为目录2的子目录
  4. [root@svr7 ~]# ls  -l  /todir                  //检查同步结果
  5. 总用量 4
  6. dr-xr-xr-x. 4 root root 4096 1130 18:50 boot

[root@svr7 ~]# ls  -l  /todir   //同步前

ls: 无法访问/todir: 没有那个文件或目录

[root@svr7 ~]# rsync  -a  /boot  /todir   //将目录1作为目录2的子目录

[root@svr7 ~]# ls  -l  /todir   //检查同步结果

总用量 4

dr-xr-xr-x. 4 root root 4096 11月 30 18:50 boot

2)将目录 /boot 下的文档同步到目录 /todir 下

copytextpop-up

  1. [root@svr7 ~]# rm  -rf  /todir                  //清理掉目录2
  2. [root@svr7 ~]# rsync  -a  /boot/  /todir          //将目录1下的文档同步到目录2
  3. [root@svr7 ~]# ls  -l  /todir                  //检查同步结果
  4. 总用量 126708
  5. -rw-r--r--. 1 root root   126426 1030 2015 config-3.10.0-327.el7.x86_64
  6. drwxr-xr-x. 2 root root     4096 1130 18:50 extlinux
  7. drwx------. 6 root root      104 12月  9 09:58 grub2
  8. .. ..

[root@svr7 ~]# rm  -rf  /todir   //清理掉目录2

[root@svr7 ~]# rsync  -a  /boot/  /todir   //将目录1下的文档同步到目录2下

[root@svr7 ~]# ls  -l  /todir   //检查同步结果

总用量 126708

-rw-r--r--. 1 root root   126426 10月 30 2015 config-3.10.0-327.el7.x86_64

drwxr-xr-x. 2 root root     4096 11月 30 18:50 extlinux

drwx------. 6 root root      104 12月  9 09:58 grub2

.. ..

3)同步效果测试

在目录/boot下新增文件a.txt,删除/todir下的子目录 grub2:

copytextpop-up

  1. [root@svr7 ~]# touch  /boot/a.txt
  2. [root@svr7 ~]# rm  -rf  /todir/grub2/ 

[root@svr7 ~]# touch  /boot/a.txt

[root@svr7 ~]# rm  -rf  /todir/grub2/

现在目录/boot和/todir目录下的内容已经不一致了:

copytextpop-up

  1. [root@svr7
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值