1、添加SMTP服務器html
bin/mail會默認使用本地sendmail發送郵件,而經過修改配置文件能夠使用外部SMTP服務器,能夠達到不使用sendmail而用外部的smtp服務器發送郵件的目的。mysql
在須要發送自動報警的服務器上修改以下文件,增長以下兩行sql
# vim /etc/mail.rc set from=doteyplay@126.com smtp=smtp.126.com set smtp-auth-user=doteyplay smtp-auth-password=*** smtp-auth=login
使用redhat的時候,在/etc/mail.rc裏改了一下外部smtp的設置,就能夠使用外部郵箱發郵件了,但在ubuntu下可能沒有/etc/mail.rc這個文件 buntu上: ubunut上mailx這個命令對應的deb包有bsd-mailx bsd-mailx對應的配置文件是/etc/mail.rc跟centos同樣 apt-get install sendmail apt-get install mailutils apt-get install bsd-mailx
有時,設置完上面的,當echo一卦郵件時,接收郵箱仍然不能接收到郵件,此時可能並非服務器上設置有問題,而是被反垃圾郵件給作掉了,若是用126的smtp服務器,發給騰訊和sina,就會出現550的錯誤(在服務器上mail中查看),騰訊說是羣發了大量郵件,即便你新申請一個,依然是這個報錯。而sina就很直接了「退信緣由:外發IP歷史信譽度低」,頗有多是以前測試一些什麼太多了,因此致使了這個問題。然而直接發給126的就沒有問題。因此,單位測試環境有問題,部到線上的時候不必定有問題數據庫
固然,這裏的SMTP服務器也能夠使用別的,好比QQ的,可是QQ只能發幾卦,在測試的時候,總報錯:smtp-server: 454 Error: authentication failed, system busy,萬惡的TX啊!因此,後來就改126的SMTP服務器了,用起來仍是至關不錯的。對於郵箱嘛,就用139郵箱吧,由於有短信提醒,一樣,在測試的時候,QQ郵箱那個慢呀……ubuntu
2、禪道自動備份腳本 vim
一、自動備份腳本centos
#vim chandao_backup.sh #!/bin/bash #Auto backup for chandao #Date: first write on 2014.7.22 #Vertion: v1.1 date=`date +%Y-%m-%d` tarball="tar -jcf /opt/backup/chandao-$date.tar.bz2 chandao/" user1=13910892224@139.com user2=15048088251@139.com if [ ! -d "/opt/backup/" ]; then mkdir -p /opt/backup/ fi cd /var/www/html/ && $tarball judge=`echo $?` if [ $judge == 0 ];then echo "backup is ok" | mail -s "Auto backup for chandao" $user1 $user2; else echo "backup is failure" | mail -s "Auto backup for chandao" $user1 $user2; fi find /opt/backup/ -type f -mtime +30 -name "*.bz2" -exec rm -rf {} \;
二、賦予腳本執行權限
bash
chmod +x chandao_backup.sh
二、任務計劃自動執行服務器
#crontab -e 0 0 * * * /bin/sh /opt/scripts/chandao_backup.sh > /dev/null 2>&1
3、數據庫自動備份腳本ide
一、自動備份腳本
#vim db_backup.sh #!/bin/bash #Auto backup for mariadb #Date: first write on 2014.7.22 #Vertion: v1.1 date=`date +%Y-%m-%d` datadir="tar -jcf /opt/backup/datadir-$date.tar.bz2 /data" #alldb="mysqldump --all-databases > /opt/backup/alldb-$date.sql" #zentaodb="mysqldump --databases zentao > /opt/backup/zentao-$date.sql" user1=13910892224@139.com user2=15048088251@139.com if [ ! -d "/opt/backup/" ]; then mkdir -p /opt/backup/ fi mysqldump --all-databases > /opt/backup/alldb-$date.sql && mysqldump --databases zentao > /opt/backup/zentao-$date.sql judge=`echo $?` if [ $judge == 0 ];then cd /opt/backup/ && tar -jcf ALLDB-$date.tar.bz2 alldb-$date.sql zentao-$date.sql --remove-files $datadir; judge1=`echo $?` if [ $judge1 == 0 ];then echo "Backup is ok!" | mail -s "Auto backup for db" $user1 $user2; else echo "Db is ok but datadir is failure!" | mail -s "Auto backup for db" $user1 $user2; fi else echo "Backup is failure,because of db backup is faild!" | mail -s "Auto backup for db" $user1 $user2; fi find /opt/backup/ -type f -mtime +30 -name "*.bz2" -exec rm -rf {} \;
二、賦予腳本執行權限
chmod +x db_backup.sh
三、任務計劃自動執行
#crontab -e 0 0 * * * /bin/sh /opt/scripts/db_backup.sh > /dev/null 2>&1
4、更新腳本版本:
數據庫備份腳本v1.2
#!/bin/bash #Auto backup for mariadb #Date: first write on 2014.7.22 #Vertion: v1.2 date=`date +%Y-%m-%d` user1=13910892224@139.com user2=15048088251@139.com main(){ tar -jcf /opt/backup/datadir-$date.tar.bz2 /data; if [ $? -eq 0 ];then /usr/local/mysql/bin/mysqldump --all-databases > /opt/backup/alldb-$date.sql; if [ $? -eq 0 ];then sleep 2 /usr/local/mysql/bin/mysqldump --databases zentao > /opt/backup/zentao-$date.sql; if [ $? -eq 0 ];then cd /opt/backup/ tar -jcf ALLDB-$date.tar.bz2 alldb-$date.sql zentao-$date.sql --remove-files \ && echo "Backup is ok!" | mail -s "Auto backup for db" $user2; else echo "Zentao db backup failure" | mail -s "Auto backup for db" $user2; fi else echo "All databases backup failure" | mail -s "Auto backup for db" $user2; fi else echo "Datadir backup failure,it's first step" | mail -s "Auto backup for db" $user2; fi find /opt/backup/ -type f -mtime +30 -name "*.bz2" -exec rm -rf {} \; } if [ ! -d "/opt/backup/" ]; then mkdir -p /opt/backup/; main; else main; fi