您的位置:首页 > 其它

Rsync+sersync数据备份

2018-01-19 16:20 190 查看
一、全网数据备份方案

1、需要备份的文件目录有(原则上,只要运维人员写入或更改的数据都需要备份)。/data,/etc/rc.local,/var/spool/cron/root等,根据不同都服务器做不同的调整
2、为了规范化,每台服务器进行本地备份时都备份到/backup目录下
3、每台WEB服务器进行本地备份时,都备份到/backup目录下以本机IP地址命名的目录中
4、打的tar包中需要包含当天的日期
5、统一存储数据备份的服务器统一采用Rsync daemon 方式提供存储备份数据都目录/backup
6、由于WEB服务器本地存储空间有限,需要将超过7天的备份数据删除
7、为了方便知道每次备份是否成功,我们需要做如下操作:
(1、在每台服务器上检查备份是否成功
(2、在存储备份数据的服务器上检查备份数据是否推送成功,并发送邮件到管理员邮箱
8、因为备份服务器空间有限,需要删除超过180天的备份数据,但每周六备份的数据要永久保留

做备份服务需要的基本步骤有:
1、 在Rsync备份服务器上安装,配置Rsync服务,实现推送
2、 在客户端服务器上,实现打包,推送,删除,定时任务推送
3、 在Rsync备份服务器上,做检查,发邮件给管理员
二、搭建Rsync备份服务端

rpm -qa rsync //查看服务是否存在

# yum install -y rsync    //安装服务
# yum install -y xinetd    //rsync依赖xinetd来管理
# rpm -qf `which rsync`   //检查服务是否正常安装
/////修改配置文件
# cp /etc/rsyncd.conf /etc/rsyncd.conf.bak
# > /etc/rsyncd.conf
# vim /etc/rsyncd.conf        //配置文件内容如下
uid = rsync
gid = rsync
address =172.16.1.15
port =873
hosts allow =172.16.1.0/24
use chroot = no
max connections = 50
pid file =/var/run/rsyncd.pid
lock file =/var/run/rsync.lock
log file =/var/log/rsyncd.log
motd file =/etc/rsyncd.motd

[backup]
path =/backup
comment = used for web-data root
read only = false
list = yes
auth users = rsyncuser
secrets file =/etc/rsyncd.passwd

echo "Welcome to Backup Server" >/etc/rsyncd.motd //写入一个提示文件

vim /etc/rsyncd.passwd //添加用户和密码

rsyncuser:password

chmod 600 /etc/rsyncd.passwd //给于最小权限

useradd rsync -s /sbin/nologin –M //创建备份用户

rsync --daemon --config=/etc/rsyncd.conf //Rsync以daemon形式运行

netstat -anptu | grep 873 //查看端口是否存在

tcp  0  0  172.16.1.15:873     0.0.0.0:*           LISTEN      7115/rsync

mkdir /backup //存放共享文件目录

chown rsync.rsync /backup/

三、搭建Rsync备份客户端(其他客户端做类似都操作)

rpm -qa rsync //查看服务是否存在

# yum install -y rsync    //安装服务
# yum install -y xinetd    //rsync依赖xinetd来管理
# rpm -qf `which rsync`   //检查服务是否正常安装
# echo "password" > /etc/rsyncd.passwd        //创建密码文件
# chmod 600 /etc/rsyncd.passwd
# mkdir /backup                //创建要备份都目录,所有备份文件都放在这个目录下
//////rsync命令测试成功
# rsync -avz /backup/ rsyncuser@172.16.1.15::backup --password-file=/etc/rsyncd.passwd

安装seRsync

wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz

tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz

mkdir /usr/local/sersync

mkdir /usr/local/sersync/conf

mkdir /usr/local/sersync/logs

mkdir /usr/local/sersync/bin

mv GNU-Linux-x86/sersync2 /usr/local/sersync/bin/

mv GNU-Linux-x86/confxml.xml /usr/local/sersync/conf/

vim conf/confxml.xml

/usr/local/sersync/bin/sersync2 -d -r -o /usr/local/sersync/conf/confxml.xml

配置文件

<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="10.0.0.121" port="8008"></host> //本地IP地址
<debug start="false"/>
<fileSystem xfs="false"/>
<filter start="false">
<exclude expression="(.).svn"></exclude>
<exclude expression="(.).gz"></exclude>
<exclude expression="^info/"></exclude>
<exclude expression="^static/"></exclude>
</filter>
<inotify>
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>

<sersync>
<localpath watch="/data/">
<remote ip="10.0.0.120" name="backup"/>            ///服务端IP地址,模板名称
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-avrtuz"/>        //Rsync传输方式
<auth start="true" users="rsyncuser" passwordfile="/etc/rsyncd.passwd"/>        ///Rsync 用户名 密码
<userDefinedPort start="true" port="873"/><!-- port=874 -->                    ///端口
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>

<plugin name="command">
<param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*)\.php"/>
<include expression="(.*)\.sh"/>
</filter>
</plugin>

<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>

</head>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Rsync sersync