#!/bin/bash
binlog_path='/data/mysql/3306/binary'
binlog_path_bak='/bak/db_backup/binlog_backup'


if [ ! -f /dev/shm/.binlog_bak_lock ];then
    echo 0 > /dev/shm/.binlog_bak_lock
fi
locked=`cat /dev/shm/.binlog_bak_lock`
if [ locked -eq 0 ];then
    mkdir -pbinlog_path_bak
    binlog_list=`ls binlog_path |grep mysql-bin |grep -v index`
        for binlog inbinlog_list;do
        binlog_diff=0
                if [ -f binlog_path_bak/binlog ];then
            diff binlog_path/binlog binlog_path_bak/binlog &>>/dev/null
            binlog_diff=?
        fi
        if [ ! -fbinlog_path_bak/binlog ] || [binlog_diff -eq 2 ];then
            echo 1 > /dev/shm/.binlog_bak_lock
            /bin/cp -arf binlog_path/binlog binlog_path_bak/binlog
            #nfs保留60天的binlog备份
            /bin/find $binlog_path_bak  -mtime +60  | xargs rm -rf
            echo 0 > /dev/shm/.binlog_bak_lock
        fi
        done
fi

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code