您好,欢迎访问一九零五行业门户网

利用Xtrabackup工具备份及恢复(MySQL DBA的必备工具)_MySQL

bitscn.com
xtrabackup------mysql dba的必备工具
注意:
1)文档参照http://www.percona.com/docs/wiki/percona-xtrabackup:start
2)mysql要使用5.1.50版本或以上。
一、xtrabackup简介及安装
1、xtrabackup  是percona的一个开源项目,可以热备份innodb ,xtradb,和myisam(会锁表),可以看做是innodb hotbackup的免费替代品。
                                                        percona support for mysql
benefitsilver
(per server)gold
(unlimited)platinum
(unlimited)
annual price $1,500/server from $15,000 from $30,000
number of servers covered per-server unlimited unlimited
number of support incidents unlimited unlimited unlimited
response time sla 60 minutes 30 minutes 30 minutes
named support contact persons 5 10 20
email, web, & chat support 650) this.width=650; style=max-width:90%> 650) this.width=650; style=max-width:90%> 650) this.width=650; style=max-width:90%>
phone support 650) this.width=650; style=max-width:90%> 650) this.width=650; style=max-width:90%> 650) this.width=650; style=max-width:90%>
login support 650) this.width=650; style=max-width:90%> 650) this.width=650; style=max-width:90%> 650) this.width=650; style=max-width:90%>
24×7 support 650) this.width=650; style=max-width:90%> 650) this.width=650; style=max-width:90%> 650) this.width=650; style=max-width:90%>
fixes for verified bugs   650) this.width=650; style=max-width:90%> 650) this.width=650; style=max-width:90%>
hot bug fixes     650) this.width=650; style=max-width:90%>
onsite system audit   option 650) this.width=650; style=max-width:90%>
covers old server versions     650) this.width=650; style=max-width:90%>
covers non-standard platforms     option
covers custom code     option
参考:http://www.percona.com/mysql-support/
先看看如何安装xtrabackup,最简单的安装方式是使用rpm包,不过想使用源代码方式安装的话,其安装方式有点古怪,因为它采用的在mysql源代码上打补丁构建的方式安装的。
2、安装:
wget http://www.percona.com/downloads/xtrabackup/xtrabackup-1.4/linux/binary/i686/
tar zxf xtrabackup-1.4.tar.gz
cd xtrabackup-1.4
./configure
make
进行到这里时,千万别make install,那样就会接着安装mysql了,正确方法是:
cd innobase/xtrabackup/
make
make install
安装参照:http://www.percona.com/docs/wiki/percona-xtrabackup:installation:from-source
3、如此一来,就会在/usr/bin目录里安装上两个有用的工具:xtrabackup、innobackupex
1)xtrabackup 只能备份innodb和xtradb两种数据表,支持在线热备份,可以在不加锁的情况下备份innodb数据表,不过此工具不能操作myisam引擎表
2)innobackupex  是一个脚本封装,封装了xtrabackup,能同时处理innodb和myisam,但在处理myisam时需要加一个读锁。
按如上的介绍,由于操作myisam时需要加读锁,这会堵塞线上服务的写操作,而innodb没有这样的限制,所以数据库中innodb表类型所占的比例越大,则越有利。实际应用中一般是直接使用innobackupex方法,它主要有三种操作方式,按手册中的介绍:
usage:
innobackup [--sleep=ms] [--compress[=level]] [--include=regexp] [--user=name]
           [--password=word] [--port=port] [--socket=socket] [--no-timestamp]
           [--ibbackup=ibbackup-binary] [--slave-info] [--stream=tar]
           [--defaults-file=my.cnf]
           [--databases=list] [--remote-host=hostname] backup-root-dir
innobackup --apply-log [--use-memory=mb] [--uncompress] [--defaults-file=my.cnf]
           [--ibbackup=ibbackup-binary] backup-dir
innobackup --copy-back [--defaults-file=my.cnf] backup-dir
――――――――――――――――――――――――――――――――――
第一个命令行是热备份mysql数据库。
带有--apply-log选项的命令是准备在一个备份上启动mysql服务。
带有--copy-back选项的命令从备份目录拷贝数据,索引,日志到my.cnf文件里规定的初始位置。
xtrabackup还可以用来moving innodb tables between servers,更多的内容可以参考官方文档及例子。
参考链接:
1.官方文档:http://www.percona.com/docs/wiki/percona-xtrabackup:xtrabackup_manual
2.xtrabackup online backup for innodb/xtradb(pdf):
http://www.percona.com/ppc2009/ppc2009_xtrabackup.pdf
    二、innobackupex 和 xtrabackup备份详解
注:innobackupex会根据/et/my.cnf来确定mysql的数据位置。
1.普通备份:
innobackupex [--defaults-file=/etc/my.cnf] --user=root [--host=192.168.1.52] [--password=xxx] [--port=3306]   /data/back_data/    2>/data/back_data/1.log
备份的目录是/data/back_data/,这里的2>/data/back_data/1.log,是将备份过程中的输出信息重定向到1.log
innobackupex-1.5.1
其它类似信息

推荐信息