mysql增量备份脚本

#!/bin/sh
/usr/bin/mysqladmin flush-logs ####产生新的二进制日志###########
DATADIR=/var/lib/mysql
BAKDIR=/backup/mysql/daily
LogFile=/backup/mysql/daily/logbak.log
HOSTNAME=`uname -n`
cd $DATADIR
FILELIST=`cat $HOSTNAME-bin.index` ###########查看二进制日志列表##############
COUNTER=0          ##计算行数,也就是文件数
for file in $FILELIST
do
               COUNTER=`expr $COUNTER + 1 `
done
                  NextNum=0
for file in  $FILELIST
do
               base=`basename $file` #########取二进制日志的文件名########
               NextNum=`expr $NextNum + 1`
      if [ $NextNum -eq $COUNTER ]
     then
             echo "skip lastest"
     else
            dest=$BAKDIR/$base #########给二进制日志的文件名和其完整路径赋给变量dest###########
                   if(test -e $dest) ###########判断二进制日志文件在备份目录中是否存在##############
                   then
                                    echo "skip exist $base" ########即不备份已经备份过的日志文件###############
                   else
                                   echo "copying $base"
                                   cp $base $BAKDIR   ############# 开始备份日志#############
                    fi
      fi
done
echo " " >> $LogFile
echo "-------------------------------------------" >> $LogFile
echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile
echo "--------------------------" >> $LogFile
echo "backup mysql binlog ok,the $base was be backuped" >> $LogFile

你可能感兴趣的:(mysql,数据库,脚本,职场,休闲)