[MySQL] innobackupex在线备份及恢复(全量和增量) Xtrabackup是由percona开发的一个开源软件,它是innodb热备工具ibbackup(收费的商业软件)的一个开源替代品。Xtrabackup由个部分组成:xtrabackup和innobackupex,其中xtrabackup工具用于备份innodb和 xtra
[MySQL] innobackupex在线备份及恢复(全量和增量)Xtrabackup是由percona开发的一个开源软件,它是innodb热备工具ibbackup(收费的商业软件)的一个开源替代品。Xtrabackup由个部分组成:xtrabackup和innobackupex,其中xtrabackup工具用于备份innodb和 xtraDB引擎的表;而innobackupex工具用于备份myisam和innodb引擎的表,本文将介绍如何用innobackupex工具做全量和增量备份。
官网:http://www.percona.com/docs/wiki/percona-xtrabackup:start
声明:以下操作最好以mysql用户执行。
首先,通过wget下载源码tar包:
wget http://www.percona.com/redir/downloads/XtraBackup/LATEST/source/percona-xtrabackup-2.1.5.tar.gz
yum install cmake gcc gcc-c++ libaio libaio-devel automake autoconf bzr bison libtool ncurses-devel zlib-devel
tar -zxvf percona-xtrabackup-2.1.5.tar.gz cd percona-xtrabackup-2.1.5
utils/build.sh脚本会根据指定的引擎版本,自动解压缩适当的MySQL源码包并进行编译,这是最简单的安装方式。当你在命令行下不带任何参数执行该脚本时,出现如下提示:
[mysql@epay100 ~/software/percona-xtrabackup-2.1.5 ]$ ./utils/build.sh Build an xtrabackup binary against the specified InnoDB flavor. Usage: build.sh CODEBASE where CODEBASE can be one of the following values or aliases: innodb51 | plugin build against InnoDB plugin in MySQL 5.1 innodb55 | 5.5 build against InnoDB in MySQL 5.5 innodb56 | 5.6,xtradb56, build against InnoDB in MySQL 5.6 | mariadb100 xtradb51 | xtradb,mariadb51 build against Percona Server with XtraDB 5.1 | mariadb52,mariadb53 xtradb55 | galera55,mariadb55 build against Percona Server with XtraDB 5.5
./utils/build.sh innodb56
cp ./innobackupex /home/mysql/admin/bin/percona-xtrabackup-2.1.5 cp ./src/xtrabackup_56 ./src/xbstream /home/mysql/admin/bin/percona-xtrabackup-2.1.5
innobackupex --defaults-file=/opt/mysql/my.cnf --user=root --password=*** /backup/mysql/data
innobackupex --defaults-file=/opt/mysql/my.cnf --user=root --password=*** --use-memory=4G --apply-log /backup/mysql/data/2013-10-29_09-05-25 innobackupex --defaults-file=/opt/mysql/my.cnf --user=root --password=*** --copy-back /backup/mysql/data/2013-10-29_09-05-25
innobackupex --defaults-file=/opt/mysql/my.cnf --user=root --password=*** --incremental-basedir=/backup/mysql/data/2013-10-29_09-05-25 --incremental /backup/mysql/data
backup_type = full-backuped from_lsn = 0 to_lsn = 563759005914 last_lsn = 563759005914
backup_type = incremental from_lsn = 563759005914 to_lsn = 574765133284 last_lsn = 574765133284
innobackupex --defaults-file=/opt/mysql/my.cnf --user=root --password=*** --incremental-basedir=/backup/mysql/data/2013-10-29_09-52-37 --incremental /backup/mysql/data
backup_type = incremental from_lsn = 574765133284 to_lsn = 574770200380 last_lsn = 574770200950
innobackupex --apply-log --redo-only BASE-DIR innobackupex --apply-log --redo-only BASE-DIR --incremental-dir=INCREMENTAL-DIR-1 innobackupex --apply-log BASE-DIR --incremental-dir=INCREMENTAL-DIR-2
innobackupex --apply-log BASE-DIR
innobackupex --copy-back BASE-DIR
131028 17:45:57 innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup' (using password: NO). innobackupex: Error: Failed to connect to MySQL server as DBD::mysql module is not installed at /home/mysql/admin/bin/percona-xtrabackup-2.1.5/innobackupex line 2913.
yum -y install perl-DBD-MySQL.x86_64