一.Inotify
inotify是一种强大的、细粒度的、异步的文件系统事件监控机制,Linux内核从2.6.13起,加入了对Inotify的支持,通过Inotify可以监控文件系统中的添加、删除、修改、移动等各种事件,但inotify只提供了C语言接口,不方便调用,所以需要先安装inotify-tools.
安装方法:yum install inotify-tools ; apt-get install inotify-tools
二.Rsync
备份工具,与tar,cpio等工具作用相同,但可以备份到别的机器,不用压缩后再传输。
目标服务器rsync配置,建立/etc/rsyncd.conf
uid = user gid = usergroup use chroot = no timeout = 600 pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock log file = /var/log/rsyncd.log [web1] path = /photo/system/ ignore errors read only = no list = no auth users = user secrets file = /etc/user.pwd
user.pwd记录user的用户名和密码,格式为user:password
源服务器shell文件
#!/bin/bash SRC=/web/system/ [email protected]::web1 /usr/bin/inotifywait -mrq -e close_write,create,attrib ${SRC} | while read D E F do /usr/bin/rsync -vzrtopg --progress $SRC $DST --password-file=/etc/picback.pwd done
picback.pwd 记录目标服务器中user的密码