首页 » MYSQL » linux,mysql自动备份,发送邮件简单shell脚本

linux,mysql自动备份,发送邮件简单shell脚本

 
yum -y install sendmail

yum -y install mutt

vi /home/root/mysql.bak.sh

#!/bin/bash

sqlPath="/home/root/mysql/"

if [ ! -d "${sqlPath}" ]; then
mkdir "${sqlPath}"
fi

fileTime=$(date +%Y%m%d);

sqlFile=${fileTime}.sql

mysqldump -u root -ppasswd dbname> ${sqlPath}${sqlFile}

#echo ${sqlFile}.tar.gz ${sqlFile}

tar -cvPzf ${sqlPath}${sqlFile}.tar.gz ${sqlPath}${sqlFile}

#推荐用163

echo "这是网站于${fileTime}数据裤本分" | mutt -s "${fileTime}数据库备份附件请及时下载" -a ${sqlPath}${sqlFile}.tar.gz -c xx@163.com

rm -rf ${sqlPath}${fileTime}*

#添加任务计划
crontab -e
59 23 * * * /home/root/mysql.bak.sh

原文链接:linux,mysql自动备份,发送邮件简单shell脚本,转载请注明来源!

1