Xtrabackup有2款主要工具:xtrabackup和innobackupex
xtrabackup只能备份和恢复innodb,而且只备份.ibd文件,.frm文件它不管,恢复时DBA要自己提供
innobackupex能备份和恢复MyISAM文件及.frm文件,并且对xtrabackup作了友好的封装,所以可用它进行全库备份
不过有个问题,在对MyISAM备份时,会加个全库读锁,阻塞写服务
关于安装
依赖包
yum install libaio libaio-devel perl-Time-HiRes curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel perl-ExtUtils-MakeMaker perl-DBD-MySQL.* package -y
到http://www.percona.com/downloads/XtraBackup/下载编译好的二进制包即可马上使用
下面分别对这2个工具做简单测试
innobackupex的备份原理如下图:
简单实例
备份
$ innobackupex --user=root --password=oracle /home/mysql/backup
模拟故障
$ mysqladmin -uroot -poracle shutdown
$ rm -rf /home/mysql/mysql/data/*
恢复
$ innobackupex --user=root --password=oracle --apply-log /home/mysql/backup/2013-10-08_14-32-27
$ innobackupex --user=root --password=oracle --copy-back /home/mysql/backup/2013-10-08_14-32-27
xtrabackup备份原理大概有如下3个过程:
① 记录LSN(log sequence number)
② 复制文件
③ 启动后台进程,不停地记录变化的redo
这个流程可以从xtrabackup备份输出结果看出来
简单测试
备份
$ xtrabackup --backup --target-dir=/home/mysql/backup
[mysql@even backup]$ ls
employees ibdata1 xtrabackup_checkpoints xtrabackup_logfile
模拟故障
关闭MySQL,把整个datadir目录清空,不过仅保留mysql和performance_schema这两个库
恢复
--恢复ibdata1,让数据文件自身保持一致
$ xtrabackup --prepare --target-dir=/home/mysql/backup/
--恢复ib_logfile0 ib_logfile1,减少恢复时间
$ xtrabackup --prepare --target-dir=/home/mysql/backup/
$ rsync -avrP /home/mysql/backup/ /home/mysql/mysql/data/
$ chown -R mysql:dba /home/mysql/mysql/data
参考文章:
http://www.percona.com/doc/percona-xtrabackup/2.1/xtrabackup_bin/xtrabackup_binary.html
http://www.baidu-ops.com/2013/05/26/xtrabackup/
http://www.banping.com/2011/07/01/xtrabackup-process-backgroud/
http://www.orczhou.com/index.php/2009/10/xtrabackup-2/
By 迦夜
2013-10-9
Early start makes easy stages