本次测试使用XtraBackup备份MySQL数据库
版本:XtraBackup2.4.5+MySQL5.7.16
下载地址:https://www.percona.com/downloads/XtraBackup/
1、安装XtraBackup
本次为了方便,使用解压版本进行安装,直接解压就可以用了。
使用过程中可能会遇到缺少perl依赖包的问题,我的方法是直接操作把镜像包里的perl都安装了,yum install -y perl*
2、简介
XtraBackup主要包括两个备份工具xtrabackup和innobackupex。其中innobackupex对xtrabackup进行了封装。本次只介绍innobackupex备份MySQL
3、全量备的操作方法
1)创建备份
#创建存储备份数据的目录
[root@rhel7 ~]# mkdir /mysqlbackup
#开始备份
[root@rhel7 ~]# innobackupex --user=root --password=123456 /mysqlbackup
161213 12:27:13 innobackupex: Starting the backup operation
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".
161213 12:27:13 version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup' as 'root' (using password: YES).
Failed to connect to MySQL server: DBI connect(';mysql_read_default_group=xtrabackup','root',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at - line 1314.
161213 12:27:13 Connecting to MySQL server host: localhost, user: root, password: set, port: 0, socket: (null)
Using server version 5.7.16
innobackupex version 2.4.5 based on MySQL server 5.7.13 Linux (x86_64) (revision id: e41c0be)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /usr/local/mysql/data
xtrabackup: open files limit requested 0, set to 1024
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 50331648
InnoDB: Number of pools: 1
161213 12:27:13 >> log scanned up to (2671643)
xtrabackup: Generating a list of tablespaces
InnoDB: Allocated tablespace ID 2 for mysql/plugin, old maximum was 0
161213 12:27:13 [01] Copying ./ibdata1 to /mysqlbackup/2016-12-13_12-27-13/ibdata1
161213 12:27:14 >> log scanned up to (2671643)
161213 12:27:15 [01] ...done
161213 12:27:15 >> log scanned up to (2671643)
161213 12:27:15 [01] Copying ./mysql/plugin.ibd to /mysqlbackup/2016-12-13_12-27-13/mysql/plugin.ibd
161213 12:27:15 [01] ...done
......
161213 12:27:16 [01] Copying ./wl/zx.ibd to /mysqlbackup/2016-12-13_12-27-13/wl/zx.ibd
161213 12:27:16 [01] ...done
161213 12:27:16 >> log scanned up to (2671643)
161213 12:27:16 Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
161213 12:27:16 Executing FLUSH TABLES WITH READ LOCK...
161213 12:27:16 Starting to backup non-InnoDB tables and files
161213 12:27:16 [01] Copying ./mysql/db.opt to /mysqlbackup/2016-12-13_12-27-13/mysql/db.opt
161213 12:27:16 [01] ...done
......
161213 12:27:18 [01] Copying ./wl/wl.frm to /mysqlbackup/2016-12-13_12-27-13/wl/wl.frm
161213 12:27:18 [01] ...done
161213 12:27:18 [01] Copying ./wl/zx.frm to /mysqlbackup/2016-12-13_12-27-13/wl/zx.frm
161213 12:27:18 [01] ...done
161213 12:27:18 Finished backing up non-InnoDB tables and files
161213 12:27:18 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
xtrabackup: The latest check point (for incremental): '2671634'
xtrabackup: Stopping log copying thread.
.161213 12:27:18 >> log scanned up to (2671643)
161213 12:27:18 Executing UNLOCK TABLES
161213 12:27:18 All tables unlocked
161213 12:27:18 [00] Copying ib_buffer_pool to /mysqlbackup/2016-12-13_12-27-13/ib_buffer_pool
161213 12:27:18 [00] ...done
161213 12:27:18 Backup created in directory '/mysqlbackup/2016-12-13_12-27-13'
161213 12:27:18 [00] Writing backup-my.cnf
161213 12:27:18 [00] ...done
161213 12:27:18 [00] Writing xtrabackup_info
161213 12:27:18 [00] ...done
xtrabackup: Transaction log of lsn (2671634) to (2671643) was copied.
161213 12:27:19 completed OK!
#在指定的目录下生成了一个时间目录
[root@rhel7 ~]# ls -l /mysqlbackup/
total 4
drwxr-x---. 7 root root 4096 Dec 13 12:27 2016-12-13_12-27-13
[root@rhel7 ~]# du -sm /mysqlbackup/*
90 /mysqlbackup/2016-12-13_12-27-13
注意:innobackupex会去读取my.cnf文件中的[mysqld]和[xtrabackup]部分,也可以使用--defaults-file指定参数文件。
2)恢复全备的数据
备份的数据不能直接使用,需要先做prepare操作(可以理解为应用日志的过程,commit的事务提交,未commit的事务回滚)