Backup一直是數據庫最重要的環節,mysql也比例外。而mysql最好的備份工具就是Percona xtrabackup和Mysql Enterprise backup(官方收費版)。php
Xtrabackup中主要包含兩個工具:html
xtrabackup:是用於熱備份innodb, xtradb表中數據的工具,不能備份其餘類型的表(Myisam表),也不能備份數據表結構。mysql
innobackupex:是將xtrabackup進行封裝的perl腳本,能夠備份和恢復MyISAM表以及數據表結構。sql
可是針對myisam的備份是須要加讀鎖的,多少會對線上業務影響。可是當前絕大部分Mysql用戶,都是用innodb,因此,myisam只是系統表使用,鎖的影響,也就能夠忽略了。數據庫
一段官方文檔的說明:app
http://www.percona.com/doc/percona-xtrabackup/2.1/manual.htmlide
It is possible to use the xtrabackup binary alone, however, the recommend way is using it through the innobackupex wrapper script and let it execute xtrabackup for you. It might be helpful to first learn how to use innobackupex, and then learn how to use xtrabackup for having a better low-level understanding or control of the tool if needed.工具
這裏,咱們就用Percona Xtrabackup來備份Mysql。測試
1. 下載軟件,進入下載連接ui
https://www.percona.com/downloads/
2. 選擇xtrabackup
3. 選擇OS版本,下載
wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.11/binary/redhat/6/x86_64/percona-xtrabackup-24-2.4.11-1.el6.x86_64.rpm
4. 安裝中可能會遇到缺乏下面包的問題:
--> Processing Dependency: libev.so.4()(64bit) for package: percona-xtrabackup-24-2.4.10-1.el6.x86_64 --> Finished Dependency Resolution Error: Package: percona-xtrabackup-24-2.4.10-1.el6.x86_64 (percona-release-x86_64) Requires: libev.so.4()(64bit)
到下面網址,下載對應系統的rpm包,並安裝
http://rpm.pbone.net/index.php3/stat/3/srodzaj/1/search/libev.so.4
下載
wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/rudi_m:/devel-snap/CentOS_CentOS-6/x86_64/libev4-4.15-7.1.x86_64.rpm
安裝
rpm -ivh libev4-4.15-7.1.x86_64.rpm
5. 下載rpm包到本地,而後安裝,發現和現有的mysql衝突conflicts with file from package mysql-community-server
# yum -y localinstall percona-xtrabackup-24-2.4.11-1.el6.x86_64.rpm ...... Transaction Check Error: file /etc/my.cnf from install of Percona-Server-shared-51-5.1.73-rel14.12.625.rhel6.x86_64 conflicts with file from package mysql-community-server-5.6.39-2.el6.x86_64
6. 先安裝一個
# yum install MySQL-shared-compat*
7. 而後再次安裝,就解決衝突問題了
# yum localinstall percona-xtrabackup-24-2.4.10-1.el6.x86_64.rpm ...... Installed: percona-xtrabackup-24.x86_64 0:2.4.10-1.el6 Dependency Installed: perl-DBD-MySQL.x86_64 0:4.013-3.el6 rsync.x86_64 0:3.0.6-12.el6 Complete!
8. 備份與恢復測試
innobackupex --defaults-file=/etc/my.cnf --user=root --password='password' /backup/20180423/
手動刪除文件
/mysql/help_topic.frm rm: remove regular file `events_stages_current.frm'? y rm: remove regular file `events_stages_history.frm'? y rm: remove regular file `events_stages_history_long.frm'? y rm: remove regular file `events_stages_summary_by_account_by_event_name.frm'?
9. 整合備份文件
innobackupex --defaults-file=/etc/my.cnf --apply-log /backup/20180423/2018-04-18_00-58-36/
10. 備份還原
innobackupex --defaults-file=/etc/my.cnf --copy-back /backup/20180423/2018-04-18_00-58-36/
能夠看到,xtrabackup已經正常工做了。
mysql備份恢復測試,請參考:
https://blog.51cto.com/hsbxxl/2107383