mysql备份脚本完成后且发送信息到邮箱

#!/bin/sh

#name: mysqlfullbackup.sh

#PS:mysql database full backup

#Write by:i.Stone


#use mysqldump --help get more detail

scriptsDir='pwd'

#mysqlDir=/var/lib/mysql

mysqlDir=/usr/bin/mysql

user=root

passPWD=123456

dataBackupDir=/tmp/mysqlback

eMailFile=$dataBackupDir/email.txt

eMail=mail@163.com

logFile=$dataBackupDir/mysqlbackup.log

DATE="$(date -I)"


echo "" > $eMailFile

echo $(date +"%y-%m-%d %H:%M:%S") >> $eMailFile

cd $dataBackupDir

dumpFile=mysql.$DATE.sql

GZDumpFile=mysql.$DATE.sql.tar.gz


/usr/bin/mysqldump  -u $user -p$passPWD --opt --default-character-set=utf8 --extended-insert=false --triggers -R --hex-blob --all-databases --flush-logs --delete-master-logs -x > $dumpFile


if [[ $? == 0 ]];then

  tar zcf $GZDumpFile $dumpFile >> $eMailFile 2>&1

  echo "BackupFilename:$GZDumpFile" >> $eMailFile

  echo "DataBase Backup Success!" >> $eMailFile

  rm -f $dumpFile


#delete daily backup files.

cd $dataBackupDir/daily

rm -rf *


#Delete old backup files(mtime>2)

$scriptsDir/rmBackup.sh


#Move Backup Files To Backup Server

$scriptsDir/rsyncBackup.sh

  if (( !$? ));then

    echo "Move Backup Files To Backup Server Success!" >> $eMailFile

  else

    echo "Move Backup Files To Backup Server Fail!" >> $emailFile

  fi

else

  echo "DataBase Backup Fail!" >> $eMailFile

fi


echo "------------------------------------------------------------" >> $logFile

cat $eMailFile >> $logFile

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值