<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>一个故事@MySQL DBA &#187; XtraBackup</title>
	<atom:link href="http://www.orczhou.com/index.php/tag/xtrabackup/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.orczhou.com</link>
	<description>一个故事@MySQL DBA</description>
	<lastBuildDate>Tue, 20 Dec 2011 15:51:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Xtrabackup Tips</title>
		<link>http://www.orczhou.com/index.php/2010/04/xtrabackup-tips/</link>
		<comments>http://www.orczhou.com/index.php/2010/04/xtrabackup-tips/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 10:41:48 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[XtraBackup]]></category>

		<guid isPermaLink="false">http://www.orczhou.com/?p=1547</guid>
		<description><![CDATA[<p><a href="http://www.percona.com/">Percona</a> are doing great job on <a href="https://launchpad.net/percona-xtrabackup">Xtrabackup</a> which <a href="http://www.orczhou.com/index.php/2009/10/xtrabackup-rc-1/">help us a lot</a>. We use it on most of our MySQL server, and it works quite fine. Xtrabckup not only helps us make the daily backup(sometimes recovery), but also help a lot   setup the replication with<strong> less </strong>impact on the online server.</p>
<p>It is pleasure to share my experience here,which may make Xtrabackup works better.</p>
<p><font color="red">1. Is the process of "copy-back" necessary?</font></p>
<p>Although the <a href="http://www.percona.com/docs/wiki/percona-xtrabackup:xtrabackup_manual#innobackupex_script">wiki</a> tells us do the "copy-back" after the "apply-log", but people found it is not necessary. Actually it will take a lot of time if you have a huge databases(e.g. > 50G). </p>
<p>Here is the usual process to make recovery from a tar backup,which I did in the last month.</p>
<p>* Extraction of the tar stream:</p>
<div class="mycode">date &#038;&#038; tar -izxvf xtrabak_20100309_0200.tar.gz &#038;&#038; date<br />
Wed Mar 10 15:17:32 CST 2010<br />
Wed Mar 10 16:10:01 CST 2010
</div>
<p>[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2010/04/xtrabackup-tips/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.percona.com/">Percona</a> are doing great job on <a href="https://launchpad.net/percona-xtrabackup">Xtrabackup</a> which <a href="http://www.orczhou.com/index.php/2009/10/xtrabackup-rc-1/">help us a lot</a>. We use it on most of our MySQL server, and it works quite fine. Xtrabckup not only helps us make the daily backup(sometimes recovery), but also help a lot   setup the replication with<strong> less </strong>impact on the online server.</p>
<p>It is pleasure to share my experience here,which may make Xtrabackup works better.</p>
<p><font color="red">1. Is the process of "copy-back" necessary?</font></p>
<p>Although the <a href="http://www.percona.com/docs/wiki/percona-xtrabackup:xtrabackup_manual#innobackupex_script">wiki</a> tells us do the "copy-back" after the "apply-log", but people found it is not necessary. Actually it will take a lot of time if you have a huge databases(e.g. > 50G). </p>
<p>Here is the usual process to make recovery from a tar backup,which I did in the last month.</p>
<p>* Extraction of the tar stream:</p>
<div class="mycode">date &#038;& tar -izxvf xtrabak_20100309_0200.tar.gz &#038;& date<br />
Wed Mar 10 15:17:32 CST 2010<br />
Wed Mar 10 16:10:01 CST 2010
</div>
<p><span id="more-1547"></span><br />
it took about 53 minutes. The tar.gz file was about 46G,and after extraction the files were total 170G.</p>
<p>* Apply log</p>
<p>it took about 18 minutes which depends on the server's QPS when making the backup and the DB size.</p>
<p>* the "copy back"</p>
<p>Now, I did the process "copy-back",which took about 63 minutes.(170G/63Min =  45MB/s). The total time spent: 53+18+63 = 134. Now we notice that "copy-back" took about half of the recovery time. </p>
<p>After that , I do not do the "copy-back", and <strong>try "mv" instead</strong>,which is quick and works fine.Since most time when recovery were doing, the situation would be an emergence. So,every minute we save will be valuable.</p>
<p><font color="red">2. Backup without any lock</font></p>
<p>Xtrabackupex is cool, and can do real online backup.Innobackupex is convenient,which also make the backup of MyISAM tables,but it will set a lock, which can help u to get the master or slave position , on all the tables. Sometime, the lock last about 60 second and most time it's ok because we always make backup at the very morning. </p>
<p>From 0.95rc innobackupex can use option &#45;&#45;no-lock to avoid this lock if ALL your tables are InnoDB and you DO NOT CARE about binary log position of backup. It's awesome.</p>
<p><font color="red">3. Again do not forget the -i</font></p>
<p>"You must use -i (&#45;&#45;ignore-zeros) option for extraction of the tar stream."</p>
<div class="mycode">tar -izxvf </div>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2010/04/xtrabackup-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xtrabackup1.0发布</title>
		<link>http://www.orczhou.com/index.php/2009/12/xtrabackup-10-release/</link>
		<comments>http://www.orczhou.com/index.php/2009/12/xtrabackup-10-release/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 12:54:06 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[XtraBackup]]></category>
		<category><![CDATA[备份]]></category>

		<guid isPermaLink="false">http://www.orczhou.com/?p=1086</guid>
		<description><![CDATA[<p>在<a href="http://www.mysqlperformanceblog.com/2009/10/24/xtrabackup-0-9-5rc/">RC版本</a>发布的两个月后，<a href="http://www.percona.com/">Percona</a>发布了Xtrabackup的<a href="http://www.mysqlperformanceblog.com/2009/12/09/xtrabackup-1-0/">Release 1.0</a>。</p>
<p>除了修复一些BUG，最大的改变在于开始支持Windows了。如果由于一些原因，你不得不在Windows上运行MySQL/InnoDB的话，也可以使用使用Xtrabackup了。</p>
<p>在Xtrabackup的<a href="http://www.percona.com/">wiki</a>上简单的介绍了一下实现的原理：[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2009/12/xtrabackup-10-release/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>在<a href="http://www.mysqlperformanceblog.com/2009/10/24/xtrabackup-0-9-5rc/">RC版本</a>发布的两个月后，<a href="http://www.percona.com/">Percona</a>发布了Xtrabackup的<a href="http://www.mysqlperformanceblog.com/2009/12/09/xtrabackup-1-0/">Release 1.0</a>。</p>
<p>除了修复一些BUG，最大的改变在于开始支持Windows了。如果由于一些原因，你不得不在Windows上运行MySQL/InnoDB的话，也可以使用使用Xtrabackup了。</p>
<p>在Xtrabackup的<a href="http://www.percona.com/">wiki</a>上简单的介绍了一下实现的原理：<span id="more-1086"></span></p>
<p>首先，在logfile中找到并记录最后一个checkpoint（“last checkpoint LSN”），然后开始从LSN的位置开始拷贝InnoDB的logfile到xtrabackup_logfile；接着，开始拷贝全部的数据文件.ibd；在拷贝全部数据文件结束之后，才停止拷贝logfile。</p>
<p>因为logfile里面记录全部的数据修改情况，所以，即时在备份过程中数据文件被修改过了，恢复时仍然能够通过解析xtrabackup_logfile保持数据的一致。</p>
<p>Tip1：Xtrabackup是一个用于备份InnoDB/XtrDB的工具，真正的在线备份（不影响数据的读写），InnoDB Hot Backup的开源替代品。</p>
<p>Tip2：在使用参数stream=tar备份的时候，你的xtrabackup_logfile可能会临时放在/tmp目录下，如果你备份的时候并发写入较大的话xtrabackup_logfile可能会很大（5G+），很可能会撑满你的/tmp目录，可以通过参数&#45;&#45;tmpdir指定目录来解决这个问题。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2009/12/xtrabackup-10-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xtrabackup第一个RC版本</title>
		<link>http://www.orczhou.com/index.php/2009/10/xtrabackup-rc-1/</link>
		<comments>http://www.orczhou.com/index.php/2009/10/xtrabackup-rc-1/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 14:19:39 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[XtraBackup]]></category>

		<guid isPermaLink="false">http://orczhou.com/?p=942</guid>
		<description><![CDATA[<p>在10月24日，<a href="http://www.percona.com/">Percona</a>发布了Xtrabackup第一个<a href="http://www.mysqlperformanceblog.com/2009/10/24/xtrabackup-0-9-5rc/">RC版本0.9.5rc</a>。</p>
<p>仍然是一点点的改进，这次Innobackupex增加了参数&#45;&#45;no-lock，待备份的数据表都是InnoDB时，而且不需要二进制日志位置，可以实现全程不锁表(否则是会有短暂的锁表)。这里有更多<a href="http://www.mysqlperformanceblog.com/2009/10/24/xtrabackup-0-9-5rc/">Ch[......]</a></p><p class='read-more'><a href='http://www.orczhou.com/index.php/2009/10/xtrabackup-rc-1/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p>在10月24日，<a href="http://www.percona.com/">Percona</a>发布了Xtrabackup第一个<a href="http://www.mysqlperformanceblog.com/2009/10/24/xtrabackup-0-9-5rc/">RC版本0.9.5rc</a>。</p>
<p>仍然是一点点的改进，这次Innobackupex增加了参数&#45;&#45;no-lock，待备份的数据表都是InnoDB时，而且不需要二进制日志位置，可以实现全程不锁表(否则是会有短暂的锁表)。这里有更多<a href="http://www.mysqlperformanceblog.com/2009/10/24/xtrabackup-0-9-5rc/">Change log</a>。这个RC版本中，发布了更多平台(RHEL4,5, Debian, FreeBSD, MacOS)的二进制包，免去了编译之苦。</p>
<p>在统计中，我们共使用了3631次备份，尚没有一次因为Xtrabackup本身的bug而备份失败。3631次中有28失败，都是因为诸如“目的地址不可写”、“磁盘分区已经满”等导致。而且也曾做过实验，在高并发写入压力下使用，Xtrabackup表现依旧正常。</p>
<p>在使用Xtrabackup过程中，也遇到过一些问题。<del datetime="2009-12-02T10:41:47+00:00">在备份同时，如果数据库写入量比较大，Xtrabackup会输出（stderr）大量的备份信息，这曾塞满了我的/tmp空间（4.6G）导致备份失败。因为希望从这些信息中获得”innobackupex: innobackup completed OK! “，所以我不得不准备更大的空间保持这些巨大的无用的日志。这个Bug已经<a href="https://bugs.launchpad.net/percona-xtrabackup/+bug/462451">提交</a>。</del>在使用&#45;&#45;stream备份的时候，xtrabackup会把xtrabackup_logfile临时（默认的）放在/tmp，有时候会把整个/tmp塞满而导致备份失败。这个只有在使用&#45;&#45;stream备份时会发生，可以通过参数&#45;&#45;tmpdir指定一个临时存放的位置，避免/tmp空间不够的问题。</p>
<p>Xtrabackup在备份5.1数据库的时候，另一个<a href="https://bugs.launchpad.net/percona-xtrabackup/+bug/420181">bug</a>是innobackupex.pl脚本的<a href="http://www.pythian.com/news/3734/mysql-51-and-innodb-hot-backup-gotcha">问题</a>，它会导致备份恢复后系统表中的general_log、slow_log不能使用。原因是5.1.12之后，mysql系统表中会增加的数据表general_log、slow_log使用了CVS存储引擎，每一个CVS表有.frm、.CSM、.CSV三个文件，而使用innobackupex.pl备份时，是不会备份.CSM、.CSV的文件的。不过这个Bug可以通过修改innobackupex.pl脚本的方法更正。修复方法如下：</p>
<blockquote><pre>
Patch innobackupex.pl to include CSV tables, specifically line 1811 from
    my $wildcard = '*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,opt,par}';
to
    my $wildcard = '*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}';
</pre>
</blockquote>
<p>关于Xtrabackup的一个等待：在它的<a href="http://www.percona.com/docs/wiki/percona-xtrabackup:xtrabackup_manual">Wiki</a>上介绍Innobackupex时有一个not implemented yet的参数[--incremental]，仍然not implemented。</p>
<p>（全文完）</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2009/10/xtrabackup-rc-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Xtrabackup备份和恢复MySQL(下)</title>
		<link>http://www.orczhou.com/index.php/2009/10/xtrabackup-2/</link>
		<comments>http://www.orczhou.com/index.php/2009/10/xtrabackup-2/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 03:44:35 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[技术细节]]></category>
		<category><![CDATA[XtraBackup]]></category>

		<guid isPermaLink="false">http://orczhou.com/?p=910</guid>
		<description><![CDATA[<p style="text-indent:0">
<strong>作者：</strong>周振兴 <a href="http://www.flickr.com/photos/26825745@N06/3933896112/" title="mail by orczhou, on Flickr"><img src="http://farm3.static.flickr.com/2614/3933896112_8ebfd42177_o.png" width="163" height="22" alt="mail" /></a><br />
<strong>来自：</strong><a href="http://www.taobaodba.com">supu@TaobaoDBA</a> 2009年10月13日星期二<br />
<strong>摘要：</strong>在<a href="http://orczhou.com/index.php/2009/09/xtrabackup-mysql-innodb/">上篇</a>中我们介绍了Xtrabackup的编译安装，以及如何使用innobackupex来备份和恢复数据库。本文将继续介绍Xtrabackup中的另一个工具xtrabackup（二进制脚本）。innobackupex对xtrabackup进行了封装可以同时备份InnoDB和MyISAM数据表，在备份MyISAM表时会进行全局锁表，如果单独使用xtrabackup，我们不仅可以实现真正的“在线”备份，还可以进行增量备份InnoDB。本文将介绍如何单独使用xtrabackup来备份你的InnoDB数据。（本文PDF版本：<a href="http://orczhou.com/wp-content/uploads/2009/10/xtrabackupe4bb8be7bb8d-1.pdf">上篇</a> <a href="http://orczhou.com/wp-content/uploads/2009/10/xtrabackupe4bb8be7bb8d-2.pdf">下篇</a>）
</p>
<p>[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2009/10/xtrabackup-2/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p style="text-indent:0">
<strong>作者：</strong>周振兴 <a href="http://www.flickr.com/photos/26825745@N06/3933896112/" title="mail by orczhou, on Flickr"><img src="http://farm3.static.flickr.com/2614/3933896112_8ebfd42177_o.png" width="163" height="22" alt="mail" /></a><br />
<strong>来自：</strong><a href="http://www.taobaodba.com">supu@TaobaoDBA</a> 2009年10月13日星期二<br />
<strong>摘要：</strong>在<a href="http://orczhou.com/index.php/2009/09/xtrabackup-mysql-innodb/">上篇</a>中我们介绍了Xtrabackup的编译安装，以及如何使用innobackupex来备份和恢复数据库。本文将继续介绍Xtrabackup中的另一个工具xtrabackup（二进制脚本）。innobackupex对xtrabackup进行了封装可以同时备份InnoDB和MyISAM数据表，在备份MyISAM表时会进行全局锁表，如果单独使用xtrabackup，我们不仅可以实现真正的“在线”备份，还可以进行增量备份InnoDB。本文将介绍如何单独使用xtrabackup来备份你的InnoDB数据。（本文PDF版本：<a href="http://orczhou.com/wp-content/uploads/2009/10/xtrabackupe4bb8be7bb8d-1.pdf">上篇</a> <a href="http://orczhou.com/wp-content/uploads/2009/10/xtrabackupe4bb8be7bb8d-2.pdf">下篇</a>）
</p>
<p><span id="more-910"></span></p>
<p style="text-indent:0">
+++++++++++++++++++++++++++++++++<br />
<strong>正文：</strong><br />
+++++++++++++++++++++++++++++++++
</p>
<p style="text-indent:0"><font size=4><b>一、	使用说明</b></font></p>
<p>本文测试环境同<a href="http://orczhou.com/index.php/2009/09/xtrabackup-mysql-innodb/">上篇</a>。</p>
<p><font size=3>1.	备份</font></p>
<p>InnoDB配置说明：</p>
<blockquote><p>
innodb_data_home_dir = ./<br />
innodb_data_file_path = ibdata1:50M:autoextend<br />
innodb_log_group_home_dir = ./<br />
innodb_log_files_in_group = 4<br />
innodb_log_file_size = 104857600
</p></blockquote>
<p>备份命令：</p>
<blockquote><p>
$xtrabackup &#45;&#45;defaults-file=/etc/my.cnf &#45;&#45;backup &#45;&#45;target-dir=/u01/xtrabackup/1/<br />
……<br />
$cd /u01/xtrabackup/1/ &#038;& ls<br />
ibdata1  test  xtrabackup_checkpoints  xtrabackup_logfile
</p></blockquote>
<p><font size=3>2.	恢复</font></p>
<p>需要执行两次xtrabackup &#45;&#45;prepare</p>
<blockquote><p>
$xtrabackup &#45;&#45;defaults-file=/etc/my.cnf &#45;&#45;prepare &#45;&#45;target-dir=/u01/xtrabackup/1/<br />
……<br />
$xtrabackup &#45;&#45;defaults-file=/etc/my.cnf &#45;&#45;prepare &#45;&#45;target-dir=/u01/xtrabackup/1/<br />
……<br />
$cd /u01/xtrabackup/1/ &#038;& ls<br />
ibdata1  ib_logfile0  ib_logfile1  ib_logfile2  ib_logfile3  test  xtrabackup_checkpoints  xtrabackup_logfile
</p></blockquote>
<p>这时候，InnoDB的全部数据文件就已经恢复了。将这些数据文件，拷贝回你的MySQL数据文件的位置就可以了。需要注意的是，xtrabackup只备份数据文件，并不备份数据表结构（.frm），所以使用xtrabackup恢复的时候，你必须有对应表结构文件（.frm）。</p>
<p style="text-indent:0"><font size=4><b>二、	增量备份</b></font></p>
<p>对比innobackupex和xtrabackup我们可以看到，innobackupex操作起来更方便，但是innobackupex会有短暂的锁表（时间依赖于MyISAM大小）。xtrabackup备份还有另一个重要特性：增量备份。（未来的版本innobackupex也可能增长该功能）</p>
<p><font size=3>1.	全量备份</font></p>
<blockquote><p>
$xtrabackup &#45;&#45;defaults-file=/etc/my.cnf &#45;&#45;backup &#45;&#45;target-dir=/u01/xtrabackup/2/<br />
……<br />
$ls /u01/xtrabackup/2/<br />
ibdata1  test  xtrabackup_checkpoints  xtrabackup_logfile
</p></blockquote>
<p><font size=3>2.	增量备份</font></p>
<blockquote><p>
$xtrabackup &#45;&#45;defaults-file=/etc/my.cnf &#45;&#45;backup &#45;&#45;target-dir=/u01/xtrabackup/2.1/  &#45;&#45;incremental-basedir=/u01/xtrabackup/2/<br />
……<br />
$ls /u01/xtrabackup/2.1/<br />
ibdata1.delta  test  xtrabackup_checkpoints  xtrabackup_logfile
</p></blockquote>
<p>在增量备份的目录下，数据文件都是以.delta结尾的。增量备份只备份上一次全量备份之后被修改过的page，所以增量备份一般只暂用较少的空间。</p>
<blockquote><p>
$cd /u01/xtrabackup/ &#038;& du &#45;&#45;max-depth=1 -h<br />
428K    ./2.1<br />
935M    ./2
</p></blockquote>
<p><font size=3>3.	增量备份恢复</font></p>
<p>我们需要分别对全量、增量备份各做一次prepare操作。</p>
<blockquote><p>
$xtrabackup &#45;&#45;defaults-file=/etc/my.cnf &#45;&#45;prepare &#45;&#45;target-dir=/u01/xtrabackup/2/<br />
……<br />
$xtrabackup &#45;&#45;prepare &#45;&#45;target-dir=/u01/xtrabackup/2/ &#45;&#45;incremental-dir=/u01/xtrabackup/2.1/<br />
……<br />
$xtrabackup &#45;&#45;prepare &#45;&#45;target-dir=/u01/xtrabackup/2/	#这一步不是必须的
</p></blockquote>
<p>这样，/u01/xtrabackup/2/下的数据文件就可以直接放到你的MySQL数据目录下，恢复数据了。</p>
<p>再次提醒，xtrabackup只备份InnoDB数据文件，表结构是不备份的，所以恢复的时候，你必须有对应表结构文件(.frm)。</p>
<p>参考文献<br />
[1].	http://www.percona.com/docs/wiki/percona-xtrabackup:start</p>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2009/10/xtrabackup-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Xtrabackup备份和恢复MySQL(上)</title>
		<link>http://www.orczhou.com/index.php/2009/09/xtrabackup-mysql-innodb/</link>
		<comments>http://www.orczhou.com/index.php/2009/09/xtrabackup-mysql-innodb/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 06:40:33 +0000</pubDate>
		<dc:creator>orczhou</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[技术细节]]></category>
		<category><![CDATA[XtraBackup]]></category>

		<guid isPermaLink="false">http://orczhou.com/?p=708</guid>
		<description><![CDATA[<p style="text-indent:0">
<strong>作者：</strong><a href="http://www.flickr.com/photos/26825745@N06/3933896112/" title="mail by orczhou, on Flickr"><img src="http://farm3.static.flickr.com/2614/3933896112_8ebfd42177_o.png" width="163" height="22" alt="mail" /></a><br />
<strong>来自：</strong>TaobaoDBA 2009年9月2日星期三<br />
<strong>摘要：</strong>本文介绍了XtraBackup的安装（编译安装）和使用。<a href="http://www.percona.com/docs/wiki/percona-xtrabackup:start">Xtrabackup</a>是一个对InnoDB做数据备份的工具，支持在线热备份（备份时不影响数据读写），是商业备份工具<a href="http://www.innodb.com/products/hot-backup/order/">InnoDB Hotbackup</a>的一个很好的<a href="http://www.ningoo.net/html/2009/using_xtrabackup_backup_mysql_database.html">替代品</a>。本文测试使用的是0.8版本，与当前最新版本是0.9<a href="http://www.percona.com/mysql/xtrabackup/0.9/">区别并不大</a>。Xtrabackup有两个主要的工具：xtrabackup、innobackupex，其中xtrabackup只能备份InnoDB和XtraDB两种数据表，innobackupex则封装了xtrabackup，同时可以备份MyISAM数据表。本文仅仅介绍了innobackupex的备份和恢复。
</p>
<p>[......]</p><p class='read-more'><a href='http://www.orczhou.com/index.php/2009/09/xtrabackup-mysql-innodb/'>继续阅读</a></p>]]></description>
			<content:encoded><![CDATA[<p style="text-indent:0">
<strong>作者：</strong><a href="http://www.flickr.com/photos/26825745@N06/3933896112/" title="mail by orczhou, on Flickr"><img src="http://farm3.static.flickr.com/2614/3933896112_8ebfd42177_o.png" width="163" height="22" alt="mail" /></a><br />
<strong>来自：</strong>TaobaoDBA 2009年9月2日星期三<br />
<strong>摘要：</strong>本文介绍了XtraBackup的安装（编译安装）和使用。<a href="http://www.percona.com/docs/wiki/percona-xtrabackup:start">Xtrabackup</a>是一个对InnoDB做数据备份的工具，支持在线热备份（备份时不影响数据读写），是商业备份工具<a href="http://www.innodb.com/products/hot-backup/order/">InnoDB Hotbackup</a>的一个很好的<a href="http://www.ningoo.net/html/2009/using_xtrabackup_backup_mysql_database.html">替代品</a>。本文测试使用的是0.8版本，与当前最新版本是0.9<a href="http://www.percona.com/mysql/xtrabackup/0.9/">区别并不大</a>。Xtrabackup有两个主要的工具：xtrabackup、innobackupex，其中xtrabackup只能备份InnoDB和XtraDB两种数据表，innobackupex则封装了xtrabackup，同时可以备份MyISAM数据表。本文仅仅介绍了innobackupex的备份和恢复。
</p>
<p><span id="more-708"></span></p>
<p style="text-indent:0">
+++++++++++++++++++++++++++++++++<br />
<strong>正文：</strong><br />
+++++++++++++++++++++++++++++++++
</p>
<p style="text-indent:0"><font size=4><b>一、 环境</b></font></p>
<p style="text-indent:0">测试主机OS：Linux RHEL AS 3</p>
<p style="text-indent:0">MySQL InnoDB环境：innodb_data_file_path = ibdata1:1G;ibdata2:1G;ibdata3:1G</p>
<p style="text-indent:0">初始化数据：</p>
<blockquote><p>
use test;<br />
CREATE TABLE items(id INT,var1 VARCHAR(10));<br />
#使用脚本随机插入约1000万数据
</p></blockquote>
<p style="text-indent:0">下载XtraBackup：</p>
<p><a href="http://www.percona.com/mysql/xtrabackup/0.8/source/">http://www.percona.com/mysql/xtrabackup/0.8/source/</a></p>
<p>这里下载的是0.8版本的源码包</p>
<p style="text-indent:0">下载MySQL源码包:</p>
<p><a href="http://dev.mysql.com/downloads/mysql/5.0.html#source">http://dev.mysql.com/downloads/mysql/5.0.html#source</a></p>
<p>因为是编译安装XtraBackup，需要使用MySQL的源代码</p>
<p><a href="$clip_image0015.gif"><img style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="clip_image001" src="$clip_image001_thumb.gif" border="0" alt="clip_image001" width="240" height="1" /></a></p>
<p style="text-indent:0"><font size=4><b>二、 编译安装</b></font></p>
<p>你也可以下载对应平台的二进制版本XtraBackup，免去编译安装的步骤，不过目前二进制版本支持的平台并不多，所以这里列出编译的步骤。</p>
<blockquote><p>
tar zxvf mysql-5.0.85.tar.gz #解压源码包</p>
<p>tar zxvf xtrabackup-0.8-src.tar.gz #解压源码包</p>
<p>mv xtrabackup-0.8-src ./mysql-5.0.85/ innobase/ #将XtraBackpu移到InnoDB的源码目录</p>
<p>#如果使用的是MySQL5.1，目录改为/mysql-5.1.*/ storage/innobase/</p>
<p>cd mysql-5.0.85/ innobase #进入源代码目录</p>
<p>patch –p2 &lt; . /xtrabackup-0.8-src/fix_innodb_for_backup.patch #给InnoDB源码打上补丁</p>
<p>#如果使用的是MySQL5.1，使用fix_innodb_for_backup51.patch</p>
<p>cd .. #进入目录mysql-5.0.85</p>
<p>./configure</p>
<p>make #我们只需要Make就可以了，不需要Make install</p>
<p>cd innobase/xtrabackup-0.8-src</p>
<p>make #编译XtraBackup；MySQL5.1<a href="https://bugs.launchpad.net/percona-xtrabackup/+bug/394374">必须</a>要使用XtraBackup0.9
</p></blockquote>
<p>编译成功后，我们会获得可执行文件xtrabackup、innobackupex。为了方便使用，分别将其拷贝到某个$PATH路径下。（我这里/u01/mysql/bin/是$PATH路径的一部分）</p>
<blockquote><p>
cp xtrabackup /u01/mysql/bin/</p>
<p>cp innobackupex-1.5.1 /u01/mysql/bin/
</p></blockquote>
<p>安装中要注意的问题：</p>
<p>编译XtraBackup；MySQL5.1<a href="https://bugs.launchpad.net/percona-xtrabackup/+bug/394374">必须</a>要使用XtraBackup0.9。</p>
<p>另外，使用MySQL5.1编译，需要简单的修改一下XtraBackup的Makefile:</p>
<blockquote><p>
#MySQL 5.0</p>
<p>#INC= -I. -I.. -I./../include -I./../../include</p>
<p>#INNODBOBJS=</p>
<p>#MySQL 5.1</p>
<p>INC= ……</p>
<p>MYSQLOBJS=
</p></blockquote>
<p>安装完成后，我们就可以使用命令innobackupex来备份我们的数据库了。</p>
<p style="text-indent:0"><font size=4><b>三、 备份</b></font></p>
<p>XtraBackup使用脚本innobackupx-1.5.1来备份你的数据库。关于innobackupx-1.5.1的详细参数，请参考<a href="http://www.percona.com/docs/wiki/percona-xtrabackup:xtrabackup_manual">http://www.percona.com/docs/wiki/percona-xtrabackup:xtrabackup_manual</a>。这里列出比较常用的备份命令：普通备份、打包（Tar）备份、压缩（Tar gzip）备份。</p>
<p>需要注意的是，innobackupex-1.5.1会根据你的/etc/my.cnf配置，来确定你的MySQL数据位置(datadir)，所以你并不需要告诉innobackupex-1.5.1你的MySQL数据在哪儿。</p>
<p><font size=3>1. 普通备份</font></p>
<blockquote><p>
innobackupex-1.5.1 &#45;&#45;user=root &#45;&#45;password=123 /u01/backup/1/innobackup/ 2&gt;/u01/backup/1/1.log
</p></blockquote>
<p>备份时间3分38秒；3G的表空间,InnoDB Free 2595840 Kb。</p>
<p>这里我们使用mysql的root用户备份，密码为123。备份的目标目录（target dir）是/u01/backup/1/innobackup/，innobackupex-1.5.1将在该目录下生成备份。例如/u01/backup/1/innobackup/2009-09-01_11-59-29就是我执行脚本后生成的备份，所有的备份文件都在该./2009-09-01_11-59-29目录下。</p>
<p>这里的2&gt;/u01/backup/1/1.log，是将备份过程中的输出信息重定向到1.log。另外innobackupex-1.5.1还支持增量备份，这里并没有测试使用。</p>
<p>那如何恢复呢？为了模拟恢复过程，我先将MySQL停止，并删除MySQL的data目录下所有数据文件。</p>
<blockquote><p>
cd mysql/data/ ;rm –rf *;</p>
<p>innobackupex-1.5.1 &#45;&#45;apply-log /u01/backup/1/innobackup/2009-09-01_11-59-29</p>
<p>innobackupex-1.5.1 &#45;&#45;apply-log /u01/backup/1/innobackup/2009-09-01_11-59-29</p>
<p>innobackupex-1.5.1 &#45;&#45;copy-back /u01/backup/1/innobackup/2009-09-01_11-59-29</p>
<p>cd /u01/mysql/data/</p>
<p>chown -R mysql:dba . #(这时候可能还需要修改datadir修改文件的所有者)
</p></blockquote>
<p>命令innobackupex-1.5.1需要指定具体哪个备份目录，先应用备份log，然后copy back。这里的备份目录是/u01/backup/1/innobackup/2009-09-01_11-59-29。恢复时间约3分钟。</p>
<p>值得一提的是，默认innobackupex-1.5.1会将二进制日志信息存放在文件xtrabackup_binlog_info中发（方便做Slave）。</p>
<p>innobackupex-1.5.1会根据/et/my.cnf来确定MySQL的数据位置。</p>
<p><font size=3>2. 打包(Tar)备份</font></p>
<p>这里基本和前面的普通备份类似，就不做详细说明了，之列出对应的命令。值得一提的是，恢复解压缩时，必须使用-i参数。</p>
<blockquote><p>
innobackupex-1.5.1 &#45;&#45;user=root &#45;&#45;password=123 &#45;&#45;stream=tar /u01/backup/2/ 2&gt;/u01/backup/2.log 1&gt;/u01/backup/2/2.tar
</p></blockquote>
<p>大约2分55秒。这里使用1&gt;做标准输出重定向。</p>
<p>恢复：</p>
<blockquote>
<p>tar –ixvf 2.tar #解压压缩 这里-i参数是必须的。</p>
<p>innobackupex-1.5.1 &#45;&#45;apply-log /u01/backup/2/innobackup</p>
<p>innobackupex-1.5.1 &#45;&#45;copy-back /u01/backup/2/innobackup</p>
<p>cd /u01/mysql/data/</p>
<p>chown -R mysql:dba . #(这时候可能还需要修改datadir修改文件的所有者)</p>
<p>mysqld_safe &#45;&#45;user=mysql &amp;
</p></blockquote>
<p><font size=3>3. 压缩(tar gzip)备份</font></p>
<blockquote><p>
innobackupex-1.5.1 &#45;&#45;user=root &#45;&#45;password=123 &#45;&#45;stream=tar /u01/backup/1/ 2&gt;/u01/backup/2.log | gzip &gt; /u01/backup/1/1.tar.gz
</p></blockquote>
<p>大约3分钟。这里使用了管道|将innobackupex-1.5.1作为gzip的标准输入。它的恢复过程，只需要使用tar –izxvf 解压对应的文件后，操作完全同普通备份。</p>
<p style="text-indent:0"><font size=4><b>四、 关于XtraBackup</b></font></p>
<p>XtraBackup还在快速的成长阶段，由<a href="http://www.percona.com/">http://www.percona.com/</a>维护。这里列出一些相关资源:</p>
<ul>
<li>
主页： <a href="http://www.percona.com/docs/wiki/percona-xtrabackup:start">http://www.percona.com/docs/wiki/percona-xtrabackup:start</a></li>
<li>Google Group: <a href="http://groups.google.com/group/percona-discussion?hl=en">http://groups.google.com/group/percona-discussion?hl=en</a></li>
<li>Launchpad: <a href="https://launchpad.net/percona-xtrabackup">https://launchpad.net/percona-xtrabackup</a></li>
<li>Manual <a href="http://www.percona.com/docs/wiki/percona-xtrabackup:xtrabackup_manual">http://www.percona.com/docs/wiki/percona-xtrabackup:xtrabackup_manual</a></li>
<li>Ningoo.net:
<p><a href="http://www.ningoo.net/html/2009/using_xtrabackup_backup_mysql_database.html">http://www.ningoo.net/html/2009/using_xtrabackup_backup_mysql_database.html</a></li>
</ul>
<p>参考文献</p>
<ol>
<li><a href="http://www.percona.com/docs/wiki/percona-xtrabackup:start">http://www.percona.com/docs/wiki/percona-xtrabackup:start</a></li>
<li><a href="http://www.ningoo.net/html/2009/using_xtrabackup_backup_mysql_database.html">http://www.ningoo.net/html/2009/using_xtrabackup_backup_mysql_database.html</a></li>
<li><a href="http://www.innodb.com/doc/hot_backup/manual.html#innobackup">http://www.innodb.com/doc/hot_backup/manual.html#innobackup</a></li>
<li><a href="http://www.ibm.com/developerworks/cn/linux/l-diffp/index.html">http://www.ibm.com/developerworks/cn/linux/l-diffp/index.html</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.orczhou.com/index.php/2009/09/xtrabackup-mysql-innodb/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

