目录
1、定时备份与实时备份区别
2、配置客户端
2.1、在客户端安装inotify-tools软件。以便提供inotifywait inotifywatch 辅助工具程序
2.2 验证:监控客户端/data_backup目录的变化
2.3 编写自动同步脚本
2.4 后台运行脚本
2.5 验证数据实时同步效果
1、定时备份与实时备份区别
| 定时备份 | 实时备份 |
| 定时备份时间固定,而且实时性差,当同步的数据长时间没有发生变化时,定时备份会比较浪费存储空间 | 只要原始位置发生变化,便会立即自动增量备份,否则一直处于等待状态 |
2、配置客户端
准备环境
| 主机 | IP地址 |
| 服务端rsync_server | 192.168.81.132/24 |
| 客户端rsync_client | 192.168.81.132 |
服务端和客户端需要提前配置好远程同步,参考上一篇博客
使用rsync服务实现远程数据同步备份-CSDN博客
2.1、在客户端安装inotify-tools软件。以便提供inotifywait inotifywatch 辅助工具程序
[root@rsync_client ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@rsync_client ~]# yum -y install epel-release
[root@rsync_client ~]# yum -y install inotify-tools
2.2 验证:监控客户端/data_backup目录的变化
| 监控选项 | 作用 |
| -m | 表示持续监控 |
| -r | 表示递归整个目录 |
| -q | 简化输出信息 |
| -e | 指定监控哪些事件 |
| modify | 修改 |
| create | 创建 |
| move | 移动 |
| delete | 删除 |
| attrib | 属性变化 |

接了来再开一个终端,并且在/data_backup目录中写入文件hello.txt,观察使用inotifywait工具有没有监控目录的变化。

2.3 编写自动同步脚本
#!/bin/bash
Monitor="inotifywait -mrq -e modify,create,attrib,move,delete /data_bakcup"
Rsync="rsync -azH --delete --password-file=/etc/rsync.pass myuser@192.168.81.132::backup" zhangsan@192.168.1.2::PengYuYan"
$Monitor | while read DIRECTORY EVERT FILE
do$Rsync
done
END

2.4 后台运行脚本

2.5 验证数据实时同步效果

接下来在客户端的被监控的目录/data_backup中,创建文件test.txt,并且往文件中输入内容“this is the test!!!”
