日期:2014-05-16  浏览次数:20819 次

mysqldump全备份脚本mysqlallbackup.sh-->(旧文档整理)

库小,大概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