限制備份速度防止資源飽和
最近在做拆庫, 於是就做了很多表遷移工作, 需要使用mysqldump
遠程備份數據, 然後發現備份時很容易就把源庫網卡打滿了. 想過用tc
命令限速, 發現有點複雜. 今天無意間看xtrabackup
文檔發現一個方法
Throttling the throughput to 10MB/sec. This requires the ‘pv’ tools; you can find them at the official site or install it from the distribution package (“apt-get install pv”)
$ innobackupex --stream=tar ./ | pv -q -L10m \
| ssh user@desthost "cat - > /data/backups/backup.tar"
Make a Streaming Backup
https://www.percona.com/doc/percona-xtrabackup/2.4/howtos/recipes_ibkx_stream.html
查看pv的介紹, 主要是輔助查看一些進度 progressbar ETA什麼的:
在google搜索mysqldump pv
基本也是些查看進度
的文章
http://landcareweb.com/questions/6489/you-mei-you-ban-fa-rang-mysqldumpjin-du-tiao-xian-shi-yong-hu-de-bei-fen-zhuang-tai
https://www.2cto.com/database/201310/248423.html
https://stackoverflow.com/questions/4852933/does-mysqldump-support-a-progress-bar
我們這裏主要目的是限速, 照貓畫虎, 可以這樣實現
導出限速
mysqldump | pv -q -L10m > xx.sql
限速導入
cat xx.sql | pv -q -L10m | mysql
導入查看進度
pv xx.sql | mysql