csync2+sqlite实现数据的高效实时的增量备份
csync2+sqlite实现数据的高效实时的增量备份
前言,测试时共两台机器: 192.168.169.112 bbs1.cheabc.com 环境:centos5 +php+ningx+mysql
一、安装配置csync2
1、相关软件包下载 wget ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/x86_64/librsync-0.9.7-13.el5.i386.rpm
wget ftp://ftp.pbone.net/mirror/ftp.freshrpms.net/pub/freshrpms/pub/dag/redhat/el5/en/i386/RPMS.dag/libtasn1-0.3.9-1.el5.rf.i386.rpm wget ftp://ftp.pbone.net/mirror/ftp.freshrpms.net/pub/freshrpms/pub/freshrpms/redhat/testing/EL5/cluster/i386/sqlite2-2.8.17-1.el5/sqlite2-2.8.17-1.el5.i386.rpm
wget ftp://ftp.pbone.net/mirror/ftp.freshrpms.net/pub/freshrpms/pub/freshrpms/redhat/testing/EL5/cluster/i386/csync2-1.34-4.el5/csync2-1.33-4.el5.i386.rpm
wget ftp://ftp.pbone.net/mirror/ftp.freshrpms.net/pub/freshrpms/pub/dag/redhat/el4/en/i386/RPMS.dag/inotify-tools-3.13-1.el4.rf.i386.rpm
ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.7.tar.gz
2、软件安装
Rpm 正常安装
echo "csync2 30865/tcp" >> /etc/services 添加为服务
1)# vi /etc/xinetd.d/csync2
service csync2
{
disable = no
protocol = tcp
socket_type = stream
wait = no
user = root
server = /usr/sbin/csync2
server_args = -i
}
# chkconfig xinetd on # vi /etc/hosts //配置主机名,分别添加到2台机器的hosts文件中.
2) vi /etc/csync2.cfg
# Csync2 Example Configuration File
# ---------------------------------
#
# Please read the documentation:
# http://oss.linbit.com/csync2/paper.pdf
nossl * *;
group mygroup
{
auto first;
# host host1 host2 (host3);
host bbs1.cheabc.com bbs2.cheabc.com; //定义组成员
# host host4@host4-eth2;
key /etc/csync.key;
# include /etc/hosts;
include /data0/htdocs/blog; //需要同步的目录
exclude *.swp; //需要排除的目录。
exclude /data0/htdocs/www/data/sessions; //需要排除同步的缓存目录。
# include /data0/htdocs/www/uc/data/avatar;
# include %homedir%/bob;
# exclude %homedir%/bob/temp;
# exclude *~ .*; //排除同步.开头的文件
# action
# {
# pattern /etc/apache/httpd.conf;
# pattern /etc/apache/sites-available/*;
# exec "/usr/sbin/apache2ctl graceful"; //可以匹配相关配置文件,并执行重启脚本
# logfile "/var/log/csync2_action.log";
# do-local;
# }
backup-directory /usr/local/webserver/backup; //防错备份目录,根据自己的需求设置。
backup-generations 0;
#auto none;
}
#
# prefix homedir
# {
# on host[12]: /export/users;
# on *: /home;
# }
3、csync2相关命令介绍
二、利用inotify实现数据的实时同步更新.
Rpm –ivh inotify-tools-3.13-1.el4.rf.i386.rpm 2、配置inotify触发同步脚本. #!/bin/bash
src=/data0/htdocs/blog
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f'
--exclude "*.swp"
-e close_write,modify,delete,create,attrib
${src}
| while read file
do
#csync2 -x >/dev/null 2>&1
csync2 -xv
echo "${src} was csynced....."
done
# chmod a+x csync2_bbs.sh
三、相关参考及注意事项. http://bbs.linuxtone.org/viewthread.php?action=printable&tid=2707 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |