inotify+rsync实现实时热备
mkdir /backup/ -p :创建一个备份目录
echo "yangdi" >/etc/rsync.password :往密码文件输入密码,需要和rsync客户端相同
chmod 600 /etc/rsync.password
chmod 4755 /usr/bin/rsync
rsync -avz --delete /backup/ rsync_backup@192.168.110.132::backup --password-file=/etc/rsync.password 推送语法:rsync -avz 本地备份目录 服务器端主机名@ip::备份模块 ----》--delete 无差异备份 删除远端文件(本地备份目录没有的,远端目录不能有)
创建一个专用来下载工具的目录:
mkdir -p /home/yangdi/tools
1.下载inotify-tools-3.14.tar.gz
2.解压tar zxf inotify-tools-3.14.tar.gz
3.cd inotify-tools-3.14
4. 命令 ./configure --prefix=/usr/local/inotify-tools-3.14
5.make&&make install
6.ln -s /usr/local/inotify-tools-3.14/ /usr/local/inotify-tools
7.cd ..
8.cd /usr/local/inotify-tools
inotify_rsync.sh脚本命令 在nfs服务器端,rsync客户端
#!/bin/bash
#inotify=/usr/local/inotify/bin/inotifywait
host=192.168.25.131
src=/data/
des=backup
user=rsync_back
/usr/local/inotify/bin/inotifywait -mrq --format '%w%f%e' -e create,close_write,delete $src \
| while read file
do
/usr/bin/rsync -avz /data/ --delete rsync_backup@192.168.25.131::backup --password-file=/etc/rsync.password
echo "${file} was rsynced" >>/tmp/rsync.log 2>&1
done
服务器端rsync.conf配置:
vim /etc/rsyncd.conf
######by deanyang 2016/10/18#####
uid = root
gid = root
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file =/var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.110.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
###################################
[backup]
commont= by dean yang
path = /data/
useradd rsync -s /sbin/nologin -M
mkdir -p /backup
chown -R rsync.rsync /backup/
echo "rsync_backup:yangdi" >/etc/rsync.password
chmod 600 /etc/rsync.password
touch /etc/rsyncd.conf
vim /etc/rsyncd.conf
rsync --daemon
echo "rsync --daemon" >>/etc/rc.local
chown -R rsync.rsync /backup/