配置linux郵件備份數(shù)據(jù)庫(kù)

  1. 使用mailx配置發(fā)送郵件

沒(méi)有安裝的先安裝一下:yum install mailx

由于阿里云的服務(wù)器屏蔽了25端口,所以只能通過(guò)ssl方式發(fā)送郵件(465端口)

修改/etc/mail.rc配置文件,在末尾加入:

set from=xxxx@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=xxxx@qq.com
set smtp-auth-password=郵箱密碼,qq郵箱為授權(quán)登錄碼
set smtp-auth=login
#set smtp-use-starttl  //這行加了會(huì)報(bào)錯(cuò),注釋掉
set ssl-verify=ignore
set nss-config-dir=/root/.certs

最后一行為證書(shū)驗(yàn)證,如果證書(shū)錯(cuò)誤會(huì)有報(bào)錯(cuò):Error in certificate: Peer's certificate issuer is not recognized.

但是不影響郵件正常發(fā)送。此問(wèn)題尚未解決。網(wǎng)上說(shuō)配置一下證書(shū),我把網(wǎng)上的操作寫(xiě)成了一個(gè)sh,但是執(zhí)行后仍然報(bào)錯(cuò)。

#!/bin/bash
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs

配置完成后測(cè)試郵件發(fā)送:

echo "hello world"|mail -v -s "test" xxxxx@qq.com
成功!
  1. 把日常備份的mysql數(shù)據(jù)庫(kù)sql發(fā)送到郵件中,防止服務(wù)器崩潰后找不到文件
#!bin/bash
cd /data/mysqlbackup
filename="`date +%y%m%d`_yii2_blog.sql"
mysqldump -uroot -p密碼 yii2_blog > $filename
echo "yii2-blog-database backup"|mail -s "yii2-blog-database" -a $filename xxx@qq.com
echo "Your database backup successfully completed"
exit 0
-a 發(fā)送郵件附件

把這個(gè)sh加入到crond服務(wù)中,可以實(shí)現(xiàn)自動(dòng)定期備份數(shù)據(jù)庫(kù)并發(fā)送到自己郵箱中

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容