#安装必要软件
####下载msmtp并安装:
# wget https://marlam.de/msmtp/releases/msmtp-1.8.13.tar.xz
# tar -xvf msmtp-1.8.13.tar.xz
# cd -xvf msmtp-1.8.13
# ./configure --prefix=/usr/local/msmtp
# make && make install
# cd /usr/local/msmtp
# mkdir etc
# vim ./etc/msmtprc
###msmtp配置
$ vim /usr/local/msmtp/etc/msmtprc
# Set default values for all following accounts.
defaults
logfile /usr/local/msmtp/msmtp.log
# The SMTP server of the provider.
account XXX@163.com
# SMTP邮件服务器地址
host smtp.163.com
# 发送的邮件Email
from XXX@163.com
auth login
tls off
# 邮件服务器登录账号
user XXX@163.com
# 邮件服务器登陆密码
password PASSWORD # 这里是授权码163邮箱授权码获取方式自行 google
# Set a default account
account default : XXX@163.com
###mutt安装配置 yum install mutt
cp /etc/Muttrc ~/.muttrc
vim ~/.muttrc
set from="Larwas_blog"
set sendmail="/usr/local/msmtp/bin/msmtp" #你的msmtp命令路径
set use_from=yes
set realname="username@163.com"
set editor="vim"
#测试
mutt 164722305@qq.com -s "内容:数据库备份"
#使用shell脚本备份数据库
#!/bin/sh
DBNAME="blog" # 数据库名
TDATE=`date +%Y-%m-%d`
DELDATE=`date -d "20 days ago" '+%Y-%m-%d'` #设置多久删除
MYSQLDUMP=/usr/local/mysql/bin/mysqldump
dir=/data/backup # 备份存储位置
if [ ! -d $dir/$TDATE ];then
mkdir -p $dir/$TDATE
fi
cd $dir/$TDATE
for i in $DBNAME;
do
$MYSQLDUMP -p`cat /root/dbpwd.dat` $i > ${i}_${TDATE}.sql
tar zcvf ${i}_${TDATE}.tar.gz ${i}_${TDATE}.sql
echo "主题:数据库备份" | mutt XXX@qq.com -a $dir/${TDATE}/${DBNAME}_${TDATE}.tar.gz -s "内容:数据库备份"
rm -rf ${i}_${TDATE}.sql
done
cd /data/www/
rm -rf $dir/$DELDATE # 删除旧的备份
$ crontab -e
#添加一行:
0 3 */3 * * /data/backup/backup.sh
#注意
本文为Larwas原创文章,转载无需和我联系,但请注明来自larwas博客 https://larwas.com
最新评论