Shell Script Logical Backup Database

Source: Internet
Author: User


[Zxw@host1 ~]$ nl shscp/dump_backup_my.sh
1 #!/bin/bash
2 #dump MySQL data once per day, the reserve last 7 days data.
3 #zhao Xiaowei
4 #2014.08.27

5 Path=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin:~/bin
6 Export PATH

7 dir= "/home/zhaoxiaowei/data_db/"
8 filename_prefix= "Data_1db_"
9 datenow= ' Date--date= +%y%m%d '
Backupfile=${dir}${filename_prefix}${datenow} ". sql"
One logfile= "/home/zxw/shdir/logfile.log"

Mailaddr= "Xxx@xxx.com xyz@xxx.com"

echo "-----------------------------" >> $LOGFILE
echo $ (date--date= +%y%m%d) >> $LOGFILE

Mysqldump-h ip-uusername-p ' XXXXXX '--events--ignore-table=mysql.events--single-transaction-a > $BACKUPFILE
Find $DIR-mtime +7-exec rm ' {} ' \; >> $LOGFILE 2>&1

If [f $BACKUPFILE]
Then
echo "xxx successfully." >> $LOGFILE
echo "$BACKUPFILE is ok!" >> $LOGFILE
Else
echo "failure when xxx." >> $LOGFILE
echo "$BACKUPFILE dump failure!!!" >> $LOGFILE
ECHO-E "$DATENOW failure when xxx" | Mail-s "$DATENOW failure when xxx" $MAILADDR
Fi


Reprint please the Source:
Blog.csdn.net/beiigang

Related Article

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.