#!/bin/bash
backuppath="/home/ccodrunner/mysqlforbak/BinLogBack"
mysqlpath="/var/lib/mysql"
logpath="/home/ccodrunner/mysqlforbak/log"
logfile="/home/ccodrunner/mysqlforbak/log/backup-1.log"
binFile="/var/lib/mysql/mysql-bin.index"
username="ucds"
password="ucds"
if [ ! -d $backuppath ];then
mkdir -p $backuppath
fi
if [ ! -d $logpath ];then
mkdir -p $logpath
fi
echo "" >> $logfile
echo "-------------------" >> $logfile
echo "BACKUP DATE:"$(date +"%Y-%m-%d %H:%M:%S") >> $logfile
echo "-------------------" >> $logfile
/usr/bin/mysqladmin -u$username -p$password flush-logs
counter=`wc -l $binFile | awk '{print $1}'`
nextNum=0
for file in `cat $binFile`
do
base_file=`basename $file`
#basename 用于截取mysql-bin.00000*文件名,去掉./mysql-bin.000005前面的./
nextNum=`expr $nextNum + 1`
if [ $nextNum -eq $counter ]
then
echo "$base_file skip !" >> $logfile
else
dest=$backuppath/$base_file
if (test -e $dest)
then
echo "$base_file exist !" >> $logfile
else
cp $mysqlpath/$base_file $backuppath
echo "$base_file copying" >> $logfile
fi
fi
done
echo [PartBack] `date +"%Y%m%d %H:%M:%S"` $nextNum Backup successful ! >> $logfile