#!/bin/bash
#configuration
db_user="root"
db_password="123456"
db_host="10.10.11.151"
db_port="3306"
db_name="crashcourse"
db_bin_dir="/home/mysql/log/"
db_bin_prefix="mysql"
db_binbackup_dir="/dir/logbin_backup/"
time_now=` date '+%Y%B%d%H%M%S' `
#start
#start
mysqladmin -h$db_host -P$db_port -u$db_user -p$db_password flush-logs
cd $db_bin_dir
for i in `cat ${db_bin_prefix}-bin.index`
do
bin_list="$bin_list `basename $i`"
done
latest=$(basename `cat ${db_bin_prefix}-bin.index|tail -n1`)
backup_list=`ls $db_binbackup_dir |grep "${db_bin_prefix}-bin"`
backup_latest=`ls $db_binbackup_dir|grep "${db_bin_prefix}-bin" |tail -n1`
for j in $bin_list
do
need_backup="YES"
for k in $backup_list
do
if [ $j = $k ]
then
need_backup="NO"
fi
done
if [ $j = $latest ]
then
need_backup="NO"
fi
if [ $j = $backup_latest ]
then
need_backup="YES"
fi
if [ $need_backup = "YES" ]
then
cp $j $db_binbackup_dir
fi
done
|