mysql-binlog server的实现

脚本:

#!/bin/sh
source $1
cd $BACKDIR
echo "Backup dir: $BACKDIR"
while:
do
LASTFILE=`ls $BACKDIR | grep -v orig | tail -n 1`
TIMESTAMP=`date +%Y%m%d%H%M%S`
SIZE=$(stat -c%s "$LASTFILE")
if[ $SIZE -gt 0 ];then
echo -e "33[31mBacking up last binlog...33[0m"
mv $LASTFILE $LASTFILE.orig$TIMESTAMP
fi
touch $LASTFILE
echo -e "33[32mstart living binlog backup...33[0m"
$MBL --raw --read-from-remote-server --stop-never --host $HOST -u $USER -p $PASS $LASTFILE
echo -e "33[31mmysqlbinlog exit with $? trying to reconnect server in $RETRY seconds33[0m"
sleep 10
done

配置文件:

MBL=/usr/local/mysql/bin/mysqlbinlog
HOST=192.168.2.100
USER=repl
PASS=Fuck@anquan1.com
BACKDIR=/logs/binlog_back/tmsdb
RETRY=10

启动:

sh script_name conf_name 

原文地址:https://www.cnblogs.com/lishug/p/13215272.html