环境:服务端 192.168.6.30(安装 rsync) /data/share
:客户端 192.168.6.38(安装 inotufy+rsync)/nfsbackup
主流程:https://www.cnblogs.com/clsn/p/7707822.html#auto_id_28
客户端安装 inotify
下面开始安装inotify-tools
[root@static-img ~]# yum install make gcc gcc-c++ #安装编译工具
[root@static-img ~]# cd /usr/local/src
[root@static-img src]# wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
[root@static-img src]# tar zxvf inotify-tools-3.14.tar.gz
[root@static-img src]# cd inotify-tools-3.14
[root@static-img inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify
[root@static-img inotify-tools-3.14]# make && make install
发现已经成功安装inotify-tools了
[root@static-img inotify-tools-3.14]# ll -d /usr/local/inotify/
drwxr-xr-x 6 root root 4096 Oct 26 12:01 /usr/local/inotify/
设置系统环境变量
[root@static-img ~]# vim /etc/profile
......
export PATH=$PATH:/usr/local/inotify/bin
[root@static-img ~]# source /etc/profile
添加库文件
[root@static-img ~]# vim /etc/ld.so.conf
/usr/local/inotify/lib
[root@static-img ~]# ldconfig
修改inotify默认参数(inotify默认内核参数值太小)
查看系统默认参数值
[root@static-img ~]# sysctl -a | grep max_queued_events
fs.inotify.max_queued_events = 16384
[root@static-img ~]# sysctl -a | grep max_user_watches
fs.inotify.max_user_watches = 8192
[root@static-img ~]# sysctl -a | grep max_user_instances
fs.inotify.max_user_instances = 128
修改参数:
[root@static-img ~]# sysctl -w fs.inotify.max_queued_events="99999999"
[root@static-img ~]# sysctl -w fs.inotify.max_user_watches="99999999"
[root@static-img ~]# sysctl -w fs.inotify.max_user_instances="65535"
脚本
#!/bin/bash Path=/data/share backup_Server=192.168.6.30 /usr/local/inotify/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /data/share | while read line do if [ -f $line ];then rsync -az $line --delete rsync_backup@$backup_Server::nfsbackup --password-file=/etc/rsync.password else cd $Path &&\ rsync -az ./ --delete rsync_backup@$backup_Server::nfsbackup --password-file=/etc/rsync.password fi done
来源:https://www.cnblogs.com/shiina-ringo/p/9963231.html