rsync服务一无差异同步

参数:
- -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 [email protected]::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/ [email protected]::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目录原本存在的文件或目录都被删除或被客户端的覆盖

猜你喜欢

转载自blog.csdn.net/liang_operations/article/details/81188189