Backup has always been the most important part of the database, and MySQL is also out of proportion. The best backup tools for mysql are Percona xtrabackup and Mysql Enterprise backup (official paid version).
Xtrabackup mainly contains two tools:
xtrabackup: It is a tool for hot backup of data in innodb and xtradb tables. It cannot back up other types of tables (Myisam tables), nor can it back up data table structures.
innobackupex: It is a perl script that encapsulates xtrabackup, which can back up and restore MyISAM tables and data table structures.
However, the backup for myisam requires a read lock, which will affect the online business to some extent. However, most of the current Mysql users use innodb, so myisam is only used by the system table, and the impact of locks can be ignored.
A description of an official document:
http://www.percona.com/doc/percona-xtrabackup/2.1/manual.html
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.
Here, we use Percona Xtrabackup to backup Mysql.
1. Download the software and enter the download link
https://www.percona.com/downloads/
2. Select xtrabackup
3. Select the OS version and download
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. During the installation, you may encounter the problem of missing the following bread:
--> 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)
Go to the following URL, download the rpm package of the corresponding system, and install it
http://rpm.pbone.net/index.php3/stat/3/srodzaj/1/search/libev.so.4
download
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
Install
rpm -ivh libev4-4.15-7.1.x86_64.rpm
5. Download the rpm package to the local, then install it, and find conflicts with the existing mysql conflict with file from package mysql-community-server
# yum localinstall percona-xtrabackup-24-2.4.10-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. Install one first
# yum install MySQL-shared-compat*
7. Then install it again to solve the conflict problem
# 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. Backup and recovery testing
innobackupex --defaults-file=/etc/my.cnf --user=root --password='password' /backup/20180423/
Delete files manually
/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. Integrate backup files
innobackupex --defaults-file=/etc/my.cnf --apply-log /backup/20180423/2018-04-18_00-58-36/
10. Backup and restore
innobackupex --defaults-file=/etc/my.cnf --copy-back /backup/20180423/2018-04-18_00-58-36/
As you can see, xtrabackup is working properly.
MySQL backup and recovery test, please refer to:
http://blog.51cto.com/hsbxxl/2107383