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