#!/bin/bash
dateDIR=`date +"%y-%m-%d"`
path=/usr/local/mysql/data
mysqladmin -uroot -p123456 flush-logs
binlog_cp=`head -n -1 $path/mysql-bin.index | sed 's/.\///'`
for i in $binlog_cp
do
mysql -uroot -p123456 -e "FLUSH TABLES WITH READ LOCK; \! cp -p $i /backup/$dateDIR/data/; UNLOCK TABLES;"
done
binlog_rm=`tail -n 1 $path/mysql-bin.index | sed 's/.\///'`
mysql -uroot -p123456 -e "purge binary logs to '$binlog_rm'"