MySQL logical backup scheme:
Logical backup for DB (in production environment due to small amount of data).
mysql_backup.sh
#!/bin/bash
Date= ' Date +%f-%h-%m '
Mkdir/opt/backup/${date}-P
Usesize= ' du-s/opt/mysql |cut-f 1 '
biaozhun= ' df/opt/|awk ' end{print ("' $usesize '" +$3)/$2*100+0.5} ' |cut-d.-f1 '
ip= ' grep ipaddr/etc/sysconfig/network-scripts/ifcfg-eth1 |cut-d =-f2 '
If [$biaozhun-ge 85]
Then
Mysqldump--user=root--flush-privileges--single-transaction--master-data=1--flush-logs--triggers--routines-- Events--hex-blob-b HBB Meta_dm_config >/opt/backup/${date}/mysqlall${date}.sql
echo "$ip disk is big,plase check" |sendmail-t "DF" [email protected]
Echo 1
Else
Mysqldump--user=root--flush-privileges--single-transaction--master-data=1-flush-logs--triggers--routines-- Events--hex-blob-b HBB Meta_dm_config >/opt/backup/${date}/mysqlall${date}.sql
Echo 2
Fi
A logical backup of a single table.
mysql_backup_per_table.sh
#!/bin/bash
Date= ' Date +%f '
Mkdir/opt/backup/${date}/hbb-p
MYSQL-E "Flush table with read lock;"
#mysql-E "use hbb;show tables;" |grep-v Table >tables_list.txt
For table_name in ' MYSQL-E ' use hbb;show tables; "|grep-v table"
Do
Mysqldump--user=root--flush-privileges--single-transaction--master-data=1--flush-logs--triggers--routines-- Events--hex-blob MySQL >/opt/backup/${date}/mysql.sql
Mysqldump--user=root--flush-privileges--single-transaction--master-data=1--flush-logs--triggers--routines-- Events--hex-blob HBB $table _name >/opt/backup/${date}/hbb/${table_name}.sql
Done
MYSQL-E "Unlock tables;"
MySQL logical backup 2 kinds of scenarios