inotify+rsync 实现文件实时备份
一.Inotifyinotify是一种强大的、细粒度的、异步的文件系统事件监控机制,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 = usergid = usergroupuse chroot = notimeout = 600pid file = /var/run/rsyncd.pidlock file = /var/run/rsyncd.locklog file = /var/log/rsyncd.logpath = /photo/system/ignore errorsread only = nolist = noauth users = usersecrets file = /etc/user.pwd user.pwd记录user的用户名和密码,格式为user:password
源服务器shell文件
#!/bin/bashSRC=/web/system/DST=user@192.168.0.162::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的密码
页:
[1]