#!/bin/sh 
date=`date +%Y-%m-%d` 
olddate=`date +%Y-%m-%d -d "-14 days"` 
data_dir=/opt/mysql/var
bak_dir=/data_bak
dbname=t_test
user=root
pass=test
mkdir -p /data_bak/$dbname/$date 
mysqldump --opt -uroot -ptest  $dbname | gzip > $bak_dir/$dbname/$date/$dbname-$date.sql.gz
test -d $bak_dir/$dbname/$olddate && rm -f $bak_dir/$dbname/$olddate
mysqladmin -uroot -ptest flush-logs 
rm_binlog=`tail -n1 $data_dir/mysql-bin.index | cut -d "/" -f2`
mysql -uroot -ptest -e "purge binary logs to '$rm_binlog'"