Zen Road and its database automatic backup and SMS, email notification script

Source: Internet
Author: User
Tags bz2

One, add an SMTP server

Modify the following file on the server that needs to send the automatic alarm, add the following two lines

# Vim/etc/mail.rcset [email protected] Smtp=smtp.126.comset Smtp-auth-user=doteyplay smtp-auth-password=*** Smtp-auth =login

Of course, the SMTP server here can also use other, such as QQ, but QQ can only send a few gua, in the test, total error: smtp-server:454 error:authentication failed, System busy, What a wicked TX! So, then changed to 126 of the SMTP server, and use it is quite good. For the mailbox, just use 139 mailbox, because there are SMS reminders, the same, in the test, QQ mailbox that slow AH ...

Second, Zen Road Automatic backup script

1. Automatic backup Script

      #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/"     [email protected]     [ email protected]     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 "  $user 1  $user 2;      else              echo  "Backup is failure"  | mail -s  "auto backup for  Chandao "  $user 1  $user 2;     fi     find /opt/ backup/ -type f -mtime +30 -name  "*.bz2"  -exec rm -rf {}  \;

2. Give script execution permission

chmod +x chandao_backup.sh

2. Task Schedule automatic execution

#crontab-E 0 0 * * */bin/sh/opt/scripts/chandao_backup.sh 2>&1/dev/null

Third, the database automatic backup script

1. Automatic backup Script

     #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 "     [email protected]      [email protected]     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 [  $judge 1  == 0 ];then                      echo  "backup is ok!"  | mail -s  "auto backup for db"   $user 1  $user 2;              else                      echo  "Db is  ok but datadir is failure! "  | mail -s  "auto backup for db"   $user 1  $user 2;              fi     else              echo  "Backup is failure, because of db backup is faild! "  | mail -s  "auto backup for db"   $user 1  $user 2;      fi     find /opt/backup/ -type f -mtime +30 -name  "*.BZ2"  -exec rm -rf {} \; 

2. Give script execution permission

chmod +x db_backup.sh

3. Task Schedule Automatic execution

#crontab-E0 0 * * */bin/sh/opt/scripts/db_backup.sh 2>&1/dev/null



This article is from the "Nmshuishui blog" blog, make sure to keep this source http://nmshuishui.blog.51cto.com/1850554/1529829

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.