innobackupex 恢复实验
[root@localhost backup]# pwd /backup [root@localhost backup]# ll 总用量 8 drwxr-xr-x 3 root root 4096 Jul 20 21:41 basebackup drwxr-xr-x 3 root root 4096 Jul 20 21:50 incbackup
全备:
[root@localhost basebackup]# innobackupex --backup /backup/basebackup [root@localhost basebackup]# ll 总用量 4 drwx------ 7 root root 4096 Jul 20 22:04 2016-07-20_22-04-44
插入数据:
mysql> create database xx; Query OK, 1 row affected (0.01 sec) mysql> use xx; Database changed mysql> create table a ( a int) -> ; Query OK, 0 rows affected (0.20 sec) mysql> insert into a select 1; Query OK, 1 row affected (0.16 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> insert into a select 2; Query OK, 1 row affected (0.02 sec)
增量备份1:
[root@localhost incbackup]# innobackupex --incremental /backup/incbackup --incremental-basedir=/backup/basebackup/2016-07-20_22-04-44 [root@localhost incbackup]# ll 总用量 4 drwx------ 8 root root 4096 Jul 20 22:08 2016-07-20_22-08-14
插入数据:
mysql> create database xx1; Query OK, 1 row affected (0.18 sec) mysql> use xx1; Database changed mysql> create table x(a int); Query OK, 0 rows affected (0.04 sec) mysql> insert into x select 1; Query OK, 1 row affected (0.02 sec) Records: 1 Duplicates: 0 Warnings: 0
增量备份2: 基于增量备份1
innobackupex --incremental /backup/incbackup --incremental-basedir=/backup/incbackup/2016-07-20_22-08-14
[root@localhost incbackup]# ll 总用量 8 drwx------ 8 root root 4096 Jul 20 22:08 2016-07-20_22-08-14 drwx------ 9 root root 4096 Jul 20 22:32 2016-07-20_22-31-55
[root@localhost 2016-07-20_22-08-14]# cat xtrabackup_checkpoints //增量1 backup_type = incremental from_lsn = 506272001 to_lsn = 506277876 last_lsn = 506277876 compact = 0 recover_binlog_info = 0
[root@localhost 2016-07-20_22-31-55]# cat xtrabackup_checkpoints //增量2 backup_type = incremental from_lsn = 506277876 to_lsn = 506282181 last_lsn = 506282181 compact = 0 recover_binlog_info = 0
[root@localhost 2016-07-20_22-04-44]# cat xtrabackup_checkpoints //全备 backup_type = full-backuped from_lsn = 0 to_lsn = 506272001 last_lsn = 506272001 compact = 0 recover_binlog_info = 0
增量备份恢复:
增量备份的恢复大体为3个步骤
*恢复完全备份
*恢复增量备份到完全备份(开始恢复的增量备份要添加--redo-only参数,到最后一次增量备份去掉--redo-only参数)
*对整体的完全备份进行恢复,回滚那些未提交的数据
[root@localhost /]# mysqladmin -uroot -p SHUTDOWN [root@localhost /]# mv data databak
[root@localhost /]# mkdir data
恢复完全备份: (注意这里一定要加--redo-only参数,该参数的意思是只应用xtrabackup日志中已提交的事务数据,不回滚还未提交的数据)
[root@localhost /]#
innobackupex --apply-log --redo-only /backup/basebackup/2016-07-20_22-04-44
恢复到增量1:
[root@localhost /]#
innobackupex --apply-log --redo-only /backup/basebackup/2016-07-20_22-04-44 --incremental-dir=/backup/incbackup/2016-07-20_22-08-14
恢复到增量2:
[root@localhost /]#
innobackupex --apply-log /backup/basebackup/2016-07-20_22-04-44 --incremental-dir=/backup/incbackup/2016-07-20_22-31-55
把所有合在一起的完全备份整体进行一次apply操作,回滚未提交的数据
[root@localhost /]# innobackupex --apply-log /backup/basebackup/2016-07-20_22-04-44
[root@localhost 2016-07-20_22-04-44]# cat xtrabackup_checkpoints backup_type = full-prepared from_lsn = 0 to_lsn = 506277876 last_lsn = 506277876 compact = 0 recover_binlog_info = 0
恢复文件到DATA目录
[root@localhost 2016-07-20_22-04-44]# innobackupex --datadir=/data --rsync --copy-back /backup/basebackup/2016-07-20_22-04-44/
mysql:mysql权限
[root@localhost 2016-07-20_22-04-44]# chown -R mysql:mysql /data
[root@localhost 2016-07-20_22-04-44]# mysqld --datadir=/data --basedir=/usr/local/mysql56 --user=mysql --debug