Rsync+sersync數據備份

一、全網數據備份方案

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/ [email protected]::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>
                  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章