mysql逻辑备份方案:
- 针对db进行逻辑备份(由于数据量较小,正在生产环境使用)。
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
- 针对单个表进行逻辑备份。
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;"