日期:2014-05-16  浏览次数:20666 次

percona mysql备份与恢复(一)

author:skate
time:2012/06/27

percona mysql备份与恢复(一)

 

XtraBackup 是开源的热备mysql的软件,可以备份InnoDB, XtraDB, and MyISAM类型的表,它是由如下三个工具组成的


1.innobackupex:有perl脚本封装的,可以备份MyISAM, InnoDB, and XtraDB类型表,推荐使用此工具
2.xtrabackup:由c语言编译的,只copy表InnoDB和XtraDB的数据
3.xbstream:允许从streaming and extracting文件压缩/抽取xbstream格式文件

 
innobackupex
innobackupex有更强的功能,它整合了xtrabackup和其他的一些功能,他不但可以全量备份/恢复,还可以基于时间的增量备份与恢复。

innobackupex备份原理
innobackupex首先调用xtrabackup来备份innodb数据文件,当xtrabackup完成后,innobackupex就查看文件xtrabackup_suspended ;然后执行“FLUSH TABLES WITH READ LOCK”来备份其他的文件

innobackupex恢复原理
innobackupex首先读取my.cnf,查看变量(datadir,innodb_data_home_dir,innodb_data_file_path,innodb_log_group_home_dir)对应的目录是存在,确定相关目录存在后,然后先copy myisam表和索引,然后在copy innodb的表、索引和日志

详细参考:http://www.percona.com/doc/percona-xtrabackup/innobackupex/how_innobackupex_works.html

 

 

下载:
[root@localhost data]# wget http://www.percona.com/redir/downloads/XtraBackup/XtraBackup-2.0.0/RPM/rhel5/i386/percona-xtrabackup-2.0.0-417.rhel5.i386.rpm

安装:
[root@localhost data]# rpm -ivh percona-xtrabackup-2.0.0-417.rhel5.i386.rpm


全量的备份与恢复

 

步骤
# innobackupex --user=root   /data/backup/
# innobackupex --apply-log   /data/backup/2012-06-27_16-32-57/
先把datadir目录更名,因为恢复时,datadir目录不为空,恢复会终止,防止意外覆盖
# innobackupex --copy-back   /data/backup/2012-06-27_16-32-57/

 

备份:
[root@localhost data]# innobackupex --user=root   /data/backup/

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Inc 2009-2012.  All Rights Reserved.

This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.

120627 16:32:51  innobackupex: Starting mysql with options:  --user='root' --unbuffered --
120627 16:32:51  innobackupex: Connected to database with mysql child process (pid=14905)
120627 16:32:57  innobackupex: Connection to database server closed
IMPORTANT: Please check that the backup run completes successfully.
           At the end of a successful backup run innobackupex
           prints "completed OK!".

innobackupex: Using mysql  Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (i686) using readline 5.1
innobackupex: Using mysql server version Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

innobackupex: Created backup directory /data/backup/2012-06-27_16-32-57
120627 16:32:57  innobackupex: Starting mysql with options:  --user='root' --unbuffered --
120627 16:32:57  innobackupex: Connected to database with mysql child process (pid=14929)
120627 16:32:59  innobackupex: Connection to database server closed

120627 16:32:59  innobackupex: Starting ibbackup with command: xtrabackup_55 --backup --suspend-at-end --target-dir=/data/backup/2012-06-27_16-32-57
innobackupex: Waiting for ibbackup (pid=14936) to suspend
innobackupex: Suspend file '/data/backup/2012-06-27_16-32-57/xtrabackup_suspended'

xtrabackup_55 version 2.0.0 for Percona Server 5.5.16 Linux (i686) (revision id: 417)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /data/mysql/usr/local/mysql/data/
xtrabackup: Target instance is assumed as followings.
xtrabackup:   innodb_data_home_dir = ./
xtrabackup:   innodb_data_file_path = ibdata1:10M:au