CentOS6.5环境下使用rsync增量同步备份文件的方法

2019-10-10 11:13:30于海丽
192.168.46.32 A机器 2 192.168.46.11 B机器

先看下A机器上,logs文件夹下的文件:

[root@h1 logs]# ll

总用量 4

-rw-r--r-- 1 root root 3 8月 30 02:29 a.txt
[root@h1 logs]#

然后,我们在B机器上,执行同步命令如下:

[root@h2 logs]# ll

总用量 0

[root@h2 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/
receiving incremental file list
logs/
logs/a.txt

sent 34 bytes received 107 bytes 282.00 bytes/sec
total size is 3 speedup is 0.02
[root@h2 logs]# ll

总用量 4

-rw-r--r-- 1 root root 3 8月 30 02:29 a.txt
[root@h2 logs]#

然后,我们在A机器上的log文件下,新增一个b.txt,再测试同步命令:

[root@h2 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/
receiving incremental file list
logs/
logs/b.txt
sent 34 bytes received 125 bytes 318.00 bytes/sec
total size is 5 speedup is 0.03
[root@h2 logs]#

通过日志,我们发现如果新增一个使用rsync仅仅同步了新增的文件: 现在我们在A服务器上的log文件夹下的a.txt里面新增一行内容,再次执行同步命令:

[root@h2 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/
receiving incremental file list
logs/a.txt
sent 37 bytes received 128 bytes 330.00 bytes/sec
total size is 9 speedup is 0.05
[root@h2 logs]#

我们发现rsync命令也能很好的识别出来 最后我们在来看下,同时改动,A服务器上的a和 b文件,一个新增一行,一个删除一行,来测下增量:

[root@h2 logs]# rsync -av --delete 192.168.46.32:/root/logs /root/logg/
receiving incremental file list
logs/
logs/a.txt
logs/b.txt
sent 65 bytes received 174 bytes 478.00 bytes/sec
total size is 10 speedup is 0.04
[root@h2 logs]#

我们发现rsync也能很好的识别出来。 最后,我们在来看下,如何在B服务器上向A服务器上发送数据,注意,散仙刚在上面的演示,是从B服务器上下载A服务器上的数据,现在我们要演示的是如何在B服务上主动发送数据到A服务器上,原理一样,都是以增量的方式的操作的,只不过写IP的方式,变换了一下位置:

[root@h2 logs]# rsync -av --delete /root/logg/logs/b.txt 192.168.46.32:/root/
sending incremental file list
b.txt
sent 87 bytes received 37 bytes 248.00 bytes/sec
total size is 10 speedup is 0.08
[root@h2 logs]#

希望本文所述对大家CentOS服务器维护有所帮助。