rsync服务一无差异同步

本文详细探讨了rsync工具在服务器间数据同步时的风险,包括推送和拉取操作可能导致的数据丢失,通过具体实验展示了无差异同步的潜在威胁,并强调了在非必要情况下应避免使用--delete参数。

参数:
- -delete


  • rsync推送备份风险

本地有什么,远程就有什么,本地没有的远端有也要删除。
服务器端的目录数据可能丢失。


  • rsync拉取风险

远端有什么,本地就有什么,远端没有的本地有也要删处。
客户端目录数据可能丢失。


  • 应用场景:

一般是有需要两台服务器之间,必须要求数据一致,且时时性有不是很高的情况,如两台负责均衡下面web服务器之间的同步,或者高可用双机配置之间的同步等,rsync无差异同步非常危险,没有特殊需要,应避免使用。


实例1:拉取动作实验
1.查看服务端目录文件

[root@rsync-A ~]# ll /liang1
total 0
-rw-r--r-- 1 rsync rsync 0 Jul 22 22:47 c
-rw-r--r-- 1 rsync rsync 0 Jul 22 22:47 d

2.将服务端目录同步到客户端的/tmp下
2.1查看/tmp目录的文件

[root@rsync-B ~]# ll /tmp/
total 0
-rw-r--r--  1 root root 0 Jul 23 03:43 a.txt
-rw-r--r--  1 root root 0 Jul 23 03:43 b.txt
-rw-r--r--  1 root root 0 Jul 23 03:43 c.txt
-rw-r--r--  1 root root 0 Jul 23 03:43 d.txt
-rw-------. 1 root root 0 Jul 22 07:16 yum.log

2.2执行拉取动作

[root@rsync-B ~]# rsync -avz --delete rsync_liang@10.0.0.129::liang /tmp --password-file=/etc/rsync.password 
receiving incremental file list
deleting .ICE-unix/
deleting yum.log
deleting d.txt
deleting c.txt
deleting b.txt
deleting a.txt
./
c
d

sent 103 bytes  received 204 bytes  614.00 bytes/sec
total size is 0  speedup is 0.00

2.3查看/tmp目录

[root@rsync-B ~]# ll /tmp/
total 0
-rw-r--r-- 1 500 500 0 Jul 22 22:47 c
-rw-r--r-- 1 500 500 0 Jul 22 22:47 d
结果:客户端tmp目录原本存在的文件或目录都被删除或被服务端的覆盖

实例2:推送动作实验
1.查看客户端/data1目录

[root@rsync-B ~]# ll /data1
total 0
-rw-r--r-- 1  500  500 0 Jul 22 22:47 a
-rw-r--r-- 1 root root 0 Jul 23 03:43 a.txt
-rw-r--r-- 1  500  500 0 Jul 22 22:47 b
-rw-r--r-- 1 root root 0 Jul 23 03:43 b.txt
-rw-r--r-- 1  500  500 0 Jul 22 22:47 c
-rw-r--r-- 1 root root 0 Jul 23 03:43 c.txt
-rw-r--r-- 1  500  500 0 Jul 22 22:47 d
-rw-r--r-- 1 root root 0 Jul 23 03:43 d.txt

2.查看服务端目录

[root@rsync-A ~]# ll /liang1
total 0
-rw-r--r-- 1 rsync rsync 0 Jul 22 22:47 c
-rw-r--r-- 1 rsync rsync 0 Jul 22 22:47 d

3.客户端执行推送动作

[root@rsync-B ~]# rsync -avz --delete /data1/ rsync_liang@10.0.0.129::liang --password-file=/etc/rsync.password 
sending incremental file list
./
a
a.txt
b
b.txt
c.txt
d.txt

sent 325 bytes  received 125 bytes  900.00 bytes/sec
total size is 0  speedup is 0.00

4.查看服务端目录

[root@rsync-A ~]# ll /liang1/         
total 0
-rw-r--r-- 1 rsync rsync 0 Jul 22 22:47 a
-rw-r--r-- 1 rsync rsync 0 Jul 23 03:43 a.txt
-rw-r--r-- 1 rsync rsync 0 Jul 22 22:47 b
-rw-r--r-- 1 rsync rsync 0 Jul 23 03:43 b.txt
-rw-r--r-- 1 rsync rsync 0 Jul 22 22:47 c
-rw-r--r-- 1 rsync rsync 0 Jul 23 03:43 c.txt
-rw-r--r-- 1 rsync rsync 0 Jul 22 22:47 d
-rw-r--r-- 1 rsync rsync 0 Jul 23 03:43 d.txt
结果:服务端/liang1目录原本存在的文件或目录都被删除或被客户端的覆盖
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值