mysql5.6 backup scripts and send messages

Source: Internet
Author: User
Tags mysql backup

1. Full library:
#!/bin/bash
#name: Full Library Backup

#backup Directory
Back_dir=date +%Y-%m-%d
#create Backup Direct
mkdir/opt/$back _dir
#definition Backup Path
back_path=/opt/$back _dir
#definition Backup command
Command=which mysqldump

Emailfile= '/tmp/email.txt '
echo "" > $emailFile
echo $ (Date +%y-%m-%d '%h:%m:%s) >> $emailFile

#backup DCOM Library
$command--login-path=backtest--add-locks-q DCOM > $back _path/$back _dir.sql

if [[$? = = 0]];then
echo $ (du-h $back _path/$back _dir.sql) >> $emailFile
echo "DataBase DCOM Backup success!!" >> $emailFile
Fi

Cat $emailFile | Mail-s "Mysql Backup" [email protected]
RM-RF $emailFile

2. Back up a table with data (only the backup data does not contain a table structure)
#!/bin/bash
Path=/opt/sql
Dir=mkdir $path/$(date +%Y-%m-%d)
dir1=$ (Date +%y-%m-%d)
MySQL--login-path=backtest-e "Show tables from DCOM" > $path/$dir 1/tables.txt

For I incat $path/$dir1/tables.txt
Do
Number=mysql --login-path=backtest -e "select count(*) from DCOM.$i" | tail -1
If [$number-GT 0]
Then echo "$i" >> $path/$dir 1/datanum.txt
else echo "$i" >> $path/$dir 1/nodatanum.txt
Fi
Done

For tables incat $path/$dir1/datanum.txt
Do
Mysqldump--login-path=backtest--add-locks-q-t DCOM $tables > $path/$dir 1/$tables. sql
Done

Rm-f $path/$dir 1/{datanum.txt,nodatanum.txt,tables.txt}

mysql5.6 backup scripts and send messages

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.