分庫備份
創(chuàng)建腳本并編寫
[root@localhost scripts]# vim bak_db_v1.sh
#!/bin/bash
備份的路徑
bak_path=/backup/db
賬號密碼
mysql_cmd='-uroot -pRedHat@123'
需要排除的數(shù)據(jù)庫
exclude_db='information_schema|mysql|performance_schema|sys'
檢驗備份路徑是否存在,不存在則創(chuàng)建
[ -d ${bak_path} ] || mkdir -p ${bak_path}
提取需要備份的數(shù)據(jù)庫,并將其寫入文件(dbname)中
mysql ${mysql_cmd} -e 'show databases' -N | egrep -v "${exclude_db}" > dbname
循環(huán)文件,針對每個庫進行備份
while read line
do
?mysqldump ${mysql_cmd} -B $line | gzip > ${bak_path}/${line}_$(date +%F).sql.gz
done < dbname
刪除臨時文件
rm -f dbname
分表備份文章來源:http://www.zghlxwxcb.cn/news/detail-621765.html
#!/bin/bash
備份的路徑
bak_path=/backup/db
賬號,密碼
mysql_cmd='-uroot -pRedHat@123'
需要排除的數(shù)據(jù)庫
exclude_db='information_schema|mysql|performance_schema|sys'
提取需要備份的數(shù)據(jù)表,并將其寫入文件(tbname)中
mysql -uroot -pRedHat@123 -N -e'show tables from abc' > tbname
循環(huán)文件,針對每個表進行備份
while read line
do
將數(shù)據(jù)表放在對應(yīng)的數(shù)據(jù)庫下面
?[ -d ${bak_path}/abc ] || mkdir -p ${bak_path}/abc
?mysqldump ${mysql_cmd} abc $line | gzip > ${bak_path}/abc/abc_${line}_$(date +%F).sql.gz
done < tbname
刪除臨時文件
rm -f tbname文章來源地址http://www.zghlxwxcb.cn/news/detail-621765.html
到了這里,關(guān)于MySQL數(shù)據(jù)庫分庫分表備份的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!