嘿嘿哈哈

通过mutt发送Gmail邮件,备份MySQL数据库
记录通过mutt发送Gmail邮件,备份MySQL数据库安装//CentOS yum install mutt ...
扫描右侧二维码阅读全文
07
2019/03

通过mutt发送Gmail邮件,备份MySQL数据库

记录通过mutt发送Gmail邮件,备份MySQL数据库

安装

//CentOS
yum install mutt

//Ubuntu
sudo apt-get install mutt

//Arch
sudo pacman -S mutt

//解决出现No authenticators available这个问题
yum install cyrus-sasl-plain -y

配置

set realname = "<first and last name>"
set from = "<gmail username>@gmail.com"
set use_from = yes
set envelope_from = yes

set smtp_url = "smtps://<gmail username>@gmail.com@smtp.gmail.com:465/"
set smtp_pass = "<app password>"
set imap_user = "<gmail username>@gmail.com"
set imap_pass = "<app password>"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set ssl_force_tls = yes

# G to get mail
bind index G imap-fetch-mail
set editor = "vim"
set charset = "utf-8"
set record = ''

测试

echo "This is an email body1." | mutt -s "This is an email subject111" test@test.com

备份脚本

#!/bin/bash

BACKUP_PATH=/mysql
CURRENT_TIME=$(date +%Y%m%d_%H%M%S)

[ ! -d "$BACKUP_PATH" ] && mkdir -p "$BACKUP_PATH"

# 要备份的数据库名
DATABASE=lib_site
FILE_GZ=${BACKUP_PATH}/$CURRENT_TIME.$DATABASE.sql.gz
/usr/local/mysql/bin/mysqldump --defaults-extra-file=/etc/my.cnf $DATABASE  | gzip > $FILE_GZ # 此处必须要用绝对路径

# 所有数据库
#mysqldump --all-databases -xxxxx

echo "数据库备份--$FILE_GZ" | mutt -s "$DATABASE备份" test@test.com -a $FILE_GZ

# 删除 7 天以前的备份 「注意写法」
cd $BACKUP_PATH
find $BACKUP_PATH -mtime +7 -name "*sql.gz"  -exec rm -f {} \;

可能会出现的问题

MYSQL 5.7 Linux脚本出现[Warning] Using a password on the command line interface can be insecure

//vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
host = localhost        //地址 添加
user = root            //用户 添加
password = 'myServerPwd'    //密码 添加

//使用
//备份导出数据库
/usr/local/mysql/bin/mysqldump --defaults-extra-file=/etc/my.cnf database > /data/mysql_bak/bak_test.sql

//导入数据库
/usr/local/mysql/bin/mysql --defaults-extra-file=/etc/my.cnf database < test_db.sql          

参考

http://www.cnblogs.com/qlqwjy/p/8325832.html
https://www.cnblogs.com/z-books/p/7550784.html

Last modification:March 8th, 2019 at 11:28 am

Leave a Comment