centos搭建rsync+inotify
根据上篇centos搭建rsync进行定时备份文章,来实现定时备份,因为很多网站数据随时都在进行变化,但定时备份只能针对某一个时间段,如果是大于这个时间段,但服务器出现问题没有备份上,那损失就很大了.
系统:centos 5.5
服务端:192.168.1.200(rsync客户端+inotify)
客服端:192.168.1.253(rsync服务端)
web目录:/var/www/vhosts
需要的软件包:rsync-3.0.7-1.el5.rf.i386.rpm inotify-tools-3.14.tar.gz
1.在1.253上安装rsync服务端
这里就不再说怎么安装rsync服务端了,请大家去看centos搭建rsync进行定时备份里的rsync服务端安装.
这里只给大家看下rsyncd.conf里的内容:
2.安装inotify
wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar zxf inotify-tools-3.14.tar.gz && cd inotify-tools-3.14
./configure
make && make install
3.配置同步更新脚本
vi rsync.sh
rsync.sh里的内容:
4.创建rsync认证
vi /etc/rsyncd/rsyncd.passwd
123456789
5.启动同步更新脚本
nohup sh /root/rsync.sh &
6.测试
在192.168.1.253的web目录里创建个tt.php
touch /var/www/vhosts/tt.php
可以在192.168.1.200的/var/www/vhosts马上就可以看到有tt.php.好了,实验成功.
系统:centos 5.5
服务端:192.168.1.200(rsync客户端+inotify)
客服端:192.168.1.253(rsync服务端)
web目录:/var/www/vhosts
需要的软件包:rsync-3.0.7-1.el5.rf.i386.rpm inotify-tools-3.14.tar.gz
1.在1.253上安装rsync服务端
这里就不再说怎么安装rsync服务端了,请大家去看centos搭建rsync进行定时备份里的rsync服务端安装.
这里只给大家看下rsyncd.conf里的内容:
pid file = /var/run/rsyncd.pid port = 873 address = 192.168.1.253 #uid = nobody #gid = nobody uid = root gid = root use chroot = yes read only = no #limit access to private LANs #hosts allow=* #192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 hosts allow = 192.168.1.200 #hosts deny=* max connections = 5 motd file = /etc/rsyncd/rsyncd.motd #This will give you a separate log file log file = /var/log/rsync.log #This will log every file transferred - up to 85,000+ per user, per sync #transfer logging = yes log format = %t %a %m %f %b syslog facility = local3 timeout = 300 [webbak] path = /var/www/vhosts list=yes ignore errors auth users = rocdk890 secrets file = /etc/rsyncd/rsyncd.secrets comment = webbak
2.安装inotify
wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar zxf inotify-tools-3.14.tar.gz && cd inotify-tools-3.14
./configure
make && make install
3.配置同步更新脚本
vi rsync.sh
rsync.sh里的内容:
#!/bin/bash src=/var/www/vhosts/ des=webbak host="192.168.1.253" /usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib $src | while read files do rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd/rsyncd.passwd $src rocdk890@$host::$des done echo "${files} was rsynced" >>/tmp/rsync.log 2>&1 done
4.创建rsync认证
vi /etc/rsyncd/rsyncd.passwd
123456789
5.启动同步更新脚本
nohup sh /root/rsync.sh &
6.测试
在192.168.1.253的web目录里创建个tt.php
touch /var/www/vhosts/tt.php
可以在192.168.1.200的/var/www/vhosts马上就可以看到有tt.php.好了,实验成功.
评论: