Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-01 13:24:05
Original
951 people have browsed it

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

Benefit Silver
(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 Yes Yes Yes
Phone Support Yes Yes Yes
Login Support Yes Yes Yes
24×7 Support Yes Yes Yes
Fixes For Verified Bugs   Yes Yes
Hot Bug Fixes     Yes
Onsite System Audit   Option Yes
Covers Old Server Versions     Yes
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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!