码迷,mamicode.com
首页 > 数据库 > 详细

mysqldump全备份脚本mysqlallbackup.sh

时间:2016-08-09 13:39:23      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

库小,大概16G左右,每天增量很小,不到100M,所以用mysqldump每天全量备份,将备份结果信息发送到email通知DBA。


mysqlallbackup.sh


:MySQL DataBase Full Backup.

# Use mysqldump --help get more detail.
# 20.20.21.11 : mysqla

set -x
# define data directy
mysqlDir=/usr/local/mysqla
# defile user,pwd
dataBackupDir=/data/backup
eMailFile=$dataBackupDir/email.txts
# email
eMail=mchdba@tom.com
# backup file
logFile=$dataBackupDir/mysqlbackup.log
#DATE=`date -l`
echo "full backup of database on 10.80.21.12 begin ......" > $eMailFile
echo $(date +%Y-%m-%d-%H:%M:%S) >> $eMailFile


cd $dataBackupDir
# defile filename
dumpFile=20_20_21_11_mysqla_$(date +%Y%m%d_%H%M%S).sql
GZDumpFile=20_20_21_11_mysqla_$(date +%Y%m%d_%H%M%S).sql.tar.gz
# $mysqlDir/bin/mysqldump  -uroot -pxxxxx --skip-opt --default-character-set=utf8 --extended-insert=false --triggers -R --hex-blob --all-databases --flush-logs --delete-master-logs --delete-master-logs --lock-tables=false  > $dumpFile
/usr/local/mysqla/bin/mysqldump  -uroot -p‘MBkangsheng#@!2010611‘  -S /tmp/mysqla.sock --default-character-set=utf8 --extended-insert=false --triggers -R --skip-opt --hex-blob --all-databases --master-data=1  --flush-logs  >$dumpFile
if [[ $?==0]]; then
echo "BackupFileName:$GZDumpFile" >> $eMailFile
echo "DataBase Backup Success!" >> $eMailFile
else
echo "DataBase Backup Fail!" >> $emailFile
fi
echo "--------------------------------------------------------" >> $logFile

cat $eMailFile >> $logFile


# send email

cat $eMailFile | mail -s "MySQL Backup" $eMail

mysqldump全备份脚本mysqlallbackup.sh

标签:

原文地址:http://www.cnblogs.com/moss_tan_jun/p/5752730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!