mysql 备份的脚本


                   mysql 备份脚本

个人生产环境使用的mysql备份脚本,写的不好.希望大家多多指教


#!/bin/bash
#BY:renzhenxing
#Date:20140207
#mysql bak scripts
#version: 0.1
R="\\033[31m";
E="\\033[0m";
B="\\033[34m";
P="\\033[35m";
date=`date +%Y%m%d`
db_dir=/opt/database_bak
db_user=root
db_password=123456
chmd5=`cat $db_dir/check.md5`
###check bak dir exist:
if [ -d $db_dir ];then
  echo -e "$R $db_dir is not exist $E , so creat $db_dir.!!!!"
###back mysql databases:
echo -e "$P start bak database 'BBS' $E"
/usr/local/mysql/bin/mysql -u $db_user -p$db_password -e "stop slave;"
#/usr/local/mysql/bin/mysqldump -u $db_user -p$db_password -B bbs | bzip2 -k -9 > $db_dir/bbs$date.bz2
/usr/local/mysql/bin/mysqldump -u $db_user -p$db_password -B bbs | bzip2 -k -9 > $db_dir/che100$date.bz2
if [ $? -eq 0 ];then
   echo " mysql is BBS databases back ok!!!,$date "
else
   echo " mysql BBS databases back failure, PLZ check backfile "
fi
/usr/local/mysql/bin/mysql -u $db_user -p$db_password -e "start slave;"
###md5sum check bak file:
md5sum $db_dir/*.bz2 >>$db_dir/md5.txt
md5sum -c $db_dir/md5.txt >>$db_dir/check.md5
###mysql rep check:
sla=`/usr/local/mysql/bin/mysql -u $db_user -p$db_password -e "show slave status\G" | grep "Yes" | wc -l`
if [ "$sla" -eq 2 ];then
   echo " Replication is OK!"
else
   echo " 主从故障,请查看!!!!!"
fi
/opt/src/sendemail/sendEmail -f [email protected] -t [email protected] -s smtp.163.com -u "`date +%F` BBS DB bak messages" -xu 18810355666 -xp 密码 -m "`date +%F` bbs db bak check file, every day AM `date +%F` auto send. /\t $chmd5">>$db_dir/sendEmail.log


你可能感兴趣的:(mysql,version,start,databases)