1 xtrabackup安装
1)解压源码包
tar -xzvf percona-xtrabackup-2.1.7.tar.gz
2)安装perl环境(DBI/DBD)
yum install perl-DBIx-Simple.noarch perl-DBD-MySQL.x86_64 perl*
3)Prerequisites
yum install cmake gcc gcc-c++ libaio libaio-devel automake autoconf
bison libtool ncurses-devel libgcrypt-devel libev-devel
4)开始编译
$ ./utils/build.sh #根据版本确认build.sh的参数
$ ./utils/build.sh innodb56 #开始编译
5)把xtrabackup_5.6复制到/usr/bin下
cp /u01/percona-xtrabackup-2.1.7/src/xtrabackup_56 /usr/bin/
2 场景描述
如下场景:
create table gyj_t2(id int,name varchar(10));
insert into gyj_t2 values(1,'AAAAA');
insert into gyj_t2 values(2,'BBBBBB');
commit;
select * from gyj_t2; #(2条记录)
3 Innobackupex备份还原过程
3.1 使用Innobackupex备份全库 同时向表中插入一条记录
innobackupex
--defaults-file=/u01/mysql/my3306/my.cnf
--user=root
--password=
--socket=/u01/mysql/my3306/run/mysql.sock
--no-timestamp
/u01/mysql/my3306/backup/xtrabackup
use jfedu;
insert into gyj_t2 values(3,'CCCCC');
commit;
3.2 停止实例3306 并且删除数据文件
mysql@localhost ~]$ mysqld_multi --defaults-extra-file=/u01/my3306/my.cnf stop 1
rm –rf /u01/mysql/my3306/data/*
** 此时数据库是无法启动的**
3.3 应用日志
innobackupex --apply-log --defaults-file=/u01/mysql/my3306/backup/xtrabackup/backup-my.cnf --user=root --password= /u01/mysql/my3306/backup/xtrabackup
3.4 拷贝备份数据到数据目录
cp -fr /u01/mysql/my3306/backup/xtrabackup/* /u01/mysql/my3306/data/
chown -R mysql:mysql /u01/mysql/my3306/data/
3.5 恢复完成!!! 启动实例
[mysql@localhost ~]$ mysqld_multi --defaults-extra-file=/u01/my3306/my.cnf start 1