码迷,mamicode.com
首页 > 数据库 > 详细

xtrabackup备份与恢复MySQL

时间:2015-01-14 18:29:59      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:xtrabackup

Xtrabackup 是percona公司的开源项目,用以实现类似innodb官方的热备份工具InnoDB Hot Backup的功能,能够非常快速地备份与恢复mysql数据库。 Xtrabackup中包含两个工具:

xtrabackup是用于热备份innodb, xtradb表中数据的工具,不能备份其他类型的表,也不能备份数据表结构;

innobackupex是将xtrabackup进行封装的perl脚本,提供了备份myisam表的能力。

下面介绍xtrabackup的全部、增量的备份与恢复。

一、下载与安装

1、下载

[root@centos64 opt]# [root@centos64 opt]# wget http://www.percona.com/downloads/XtraBackup/XtraBackup-2.1.9/RPM/rhel6/i386/percona-xtrabackup-2.1.9-744.rhel6.i686.rpm

2、安装依赖库

[root@centos64 opt]# yum install cmake gcc gcc-c++ libaio libaio-devel automake autoconf bzr bison libtool ncurses-devel zlib-devel perl-Time-HiRes perl-DBD-MySQL -y

3、解压

[root@centos64 opt]# rpm -ivh percona-xtrabackup-2.1.9-744.rhel6.i686.rpm 

至此,Xtrabackup 初步安装完成。

其中,
innobackupex是我们要使用的备份工具;
xtrabackup是被封装在innobackupex之中的,innobackupex运行时需要调用它;

4、对某个数据库进行全部备份的命令介绍

innobackupex --user=root --password=root --defaults-file=/etc/my.cnf --database=test --stream=tar /tmp/data/ 2>/tmp/data/err.log|gzip 1>/tmp/data/test.tar.gz

说明:

--database=test 单独对test数据库做备份 ,若是不添加此参数那就那就是对全库做备份
 2>/tmp/data/err.log 输出信息写入日志中
 1>/tmp/data/test.tar.gz 打包压缩存储到该文件中

二、对数据库的全部备份与恢复

(1)先进入mysql里创建一个新的test数据库

mysql> drop database test;

mysql> create database test;

mysql> use test;

mysql> create table test (id int);

mysql> insert into test values(1);

mysql> insert into test values(2);

mysql> insert into test values(3);

mysql> insert into test values(4);

mysql> insert into test values(5);

mysql> flush privileges;

(2)然后备份test的整个数据库

[root@centos64_1 ~]# vi /tmp/backup.sh

[root@centos64_1 ~]# chmod +x /tmp/backup.sh

backup.sh脚本内容如下:

#!/bin/bash  

user=‘root‘ 

passwd=‘root‘ 

database=test 

my_config=‘/etc/my.cnf‘ 

log=$database-$(date +%Y%m%d%H%M).log  

str=$database-$(date +%Y%m%d%H%M).tar.gz  

backup_dir=‘/tmp/data‘ 

echo "Start to backup at $(date +%Y%m%d%H%M)"  

if [ ! -d "$backup_dir" ];then  

    mkdir $backup_dir  

fi  

innobackupex --user=$user --password=$passwd --defaults-file=$my_config --database=$database --stream=tar $backup_dir 2>$backup_dir/$log | gzip 1>$backup_dir/$str  

if [ $? -eq 0 ];then  

    echo "Backup is finish! at $(date +%Y%m%d%H%M)"  

    exit 0  

else  

    echo "Backup is Fail! at $(date +%Y%m%d%H%M)"  

    exit 1  

fi

运行脚本:

[root@centos64_1 ~]# sh /tmp/backup.sh 

Start to backup at 201501141131

Backup is finish! at 201501141131

[root@centos64_1 ~]# 

然后到data里查看结果:

[root@centos64_1 ~]# cd /tmp/data/

[root@centos64_1 data]# ll

total 40

-rw-r--r-- 1 root root  3493 Jan 14 15:50 test-201501141550.log

-rw-r--r-- 1 root root 36031 Jan 14 15:50 test-201501141550.tar.gz

[root@centos64_1 data]# cat test-201501141550.log 


InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy

and Percona LLC and/or its affiliates 2009-2013.  All Rights Reserved.


This software is published under

the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.


Get the latest version of Percona XtraBackup, documentation, and help resources:

http://www.percona.com/xb/p


150114 15:50:33  innobackupex: Connecting to MySQL server with DSN ‘dbi:mysql:;mysql_read_default_file=/etc/my.cnf;mysql_read_default_group=xtrabackup‘ as ‘root‘  (using password: YES).

150114 15:50:33  innobackupex: Connected to MySQL server

150114 15:50:33  innobackupex: Executing a version check against the server...


# A software update is available:

#   * Security vulnerability. See http://www.mysqlperformanceblog.com/2012/09/10/introducing-the-version-check-feature-in-percona-toolkit/

150114 15:50:41  innobackupex: Done.

IMPORTANT: Please check that the backup run completes successfully.

           At the end of a successful backup run innobackupex

           prints "completed OK!".

innobackupex: Using mysql server version 5.5.14-log

innobackupex: Created backup directory /tmp/data

150114 15:50:41  innobackupex: Starting ibbackup with command: xtrabackup_55  --defaults-file="/etc/my.cnf"  --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/tmp --tmpdir=/tmp --stream=tar

innobackupex: Waiting for ibbackup (pid=25747) to suspend

innobackupex: Suspend file ‘/tmp/xtrabackup_suspended_2‘

xtrabackup_55 version 2.1.9 for Percona Server 5.5.35 Linux (i686) (revision id: 744)

xtrabackup: uses posix_fadvise().

xtrabackup: cd to /opt/data/mysql

xtrabackup: open files limit requested 0, set to 1024

xtrabackup: using the following InnoDB configuration:

xtrabackup:   innodb_data_home_dir = ./

xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend

xtrabackup:   innodb_log_group_home_dir = ./

xtrabackup:   innodb_log_files_in_group = 2

xtrabackup:   innodb_log_file_size = 5242880

>> log scanned up to (1603244)

[01] Streaming ./ibdata1

>> log scanned up to (1603244)

[01]        ...done

>> log scanned up to (1603244)

xtrabackup: Creating suspend file ‘/tmp/xtrabackup_suspended_2‘ with pid ‘25747‘

150114 15:50:44  innobackupex: Continuing after ibbackup has suspended

150114 15:50:44  innobackupex: Starting to lock all tables...

>> log scanned up to (1603244)

150114 15:50:45  innobackupex: All tables locked and flushed to disk

150114 15:50:45  innobackupex: Starting to backup non-InnoDB tables and files

innobackupex: in subdirectories of ‘/opt/data/mysql‘

innobackupex: Backing up file ‘/opt/data/mysql/test/test.frm‘

innobackupex: Backing up file ‘/opt/data/mysql/test/db.opt‘

150114 15:50:45  innobackupex: Finished backing up non-InnoDB tables and files

150114 15:50:45  innobackupex: Waiting for log copying to finish

xtrabackup: The latest check point (for incremental): ‘1603244‘

xtrabackup: Stopping log copying thread.

.>> log scanned up to (1603244)

xtrabackup: Creating suspend file ‘/tmp/xtrabackup_log_copied‘ with pid ‘25747‘

xtrabackup: Transaction log of lsn (1603244) to (1603244) was copied.

150114 15:50:46  innobackupex: All tables unlocked

innobackupex: Backup created in directory ‘/tmp/data‘

innobackupex: MySQL binlog position: filename ‘mysql-bin.000007‘, position 107

150114 15:50:46  innobackupex: Connection to database server closed

innobackupex: You must use -i (--ignore-zeros) option for extraction of the tar stream.

150114 15:50:46  innobackupex: completed OK!

[root@centos64_1 data]# 

可以看到备份完成了.

(3)恢复数据库
先关闭mysql服务,然后再删除test数据库文件.

[root@centos64 opt]# service mysqld stop

[root@centos64 mysql]# pwd

/opt/data/mysql

[root@centos64 mysql]# rm -rf test/

开始恢复数据库,先把之前/tmp/data里的数据库压缩版给解压。

[root@centos64_1 data]# mkdir -p /tmp/restore

[root@centos64_1 data]# tar -izxvf test-201501141550.tar.gz -C /tmp/restore

注意:这里tar解包必须使用-i参数,否则解压出来的文件只有一个backup-my.cnf

此时的目录结构如下:

[root@centos64_1 restore]# ll

total 18456

-rw-r--r-- 1 root root      260 Jan 14 15:50 backup-my.cnf

-rw-rw---- 1 root root 18874368 Jan 14 15:37 ibdata1

drwxr-xr-x 2 root root     4096 Jan 14 16:13 test

-rw-r--r-- 1 root root       13 Jan 14 15:50 xtrabackup_binary

-rw-r--r-- 1 root root       23 Jan 14 15:50 xtrabackup_binlog_info

-rw-rw---- 1 root root       89 Jan 14 15:50 xtrabackup_checkpoints

-rw-rw---- 1 root root     2560 Jan 14 15:50 xtrabackup_logfile


然后将备份文件中的日志应用到备份文件中的数据文件上。

[root@centos64_1 data]# innobackupex --user=root --password=root --apply-log /tmp/restore/


InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy

and Percona LLC and/or its affiliates 2009-2013.  All Rights Reserved.


This software is published under

the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.


Get the latest version of Percona XtraBackup, documentation, and help resources:

http://www.percona.com/xb/p


IMPORTANT: Please check that the apply-log run completes successfully.

           At the end of a successful apply-log run innobackupex

           prints "completed OK!".


150114 16:17:45  innobackupex: Starting ibbackup with command: xtrabackup_55  --defaults-file="/tmp/restore/backup-my.cnf"  --defaults-group="mysqld" --prepare --target-dir=/tmp/restore --tmpdir=/tmp


xtrabackup_55 version 2.1.9 for Percona Server 5.5.35 Linux (i686) (revision id: 744)

xtrabackup: cd to /tmp/restore

xtrabackup: This target seems to be not prepared yet.

xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(1603244)

xtrabackup: using the following InnoDB configuration for recovery:

xtrabackup:   innodb_data_home_dir = ./

xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend

xtrabackup:   innodb_log_group_home_dir = ./

xtrabackup:   innodb_log_files_in_group = 1

xtrabackup:   innodb_log_file_size = 2097152

xtrabackup: using the following InnoDB configuration for recovery:

xtrabackup:   innodb_data_home_dir = ./

xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend

xtrabackup:   innodb_log_group_home_dir = ./

xtrabackup:   innodb_log_files_in_group = 1

xtrabackup:   innodb_log_file_size = 2097152

xtrabackup: Starting InnoDB instance for recovery.

xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)

150114 16:17:45 InnoDB: The InnoDB memory heap is disabled

150114 16:17:45 InnoDB: Mutexes and rw_locks use GCC atomic builtins

150114 16:17:45 InnoDB: Compressed tables use zlib 1.2.3

150114 16:17:45 InnoDB: Initializing buffer pool, size = 100.0M

150114 16:17:45 InnoDB: Completed initialization of buffer pool

150114 16:17:45 InnoDB: highest supported file format is Barracuda.

150114 16:17:46  InnoDB: Waiting for the background threads to start

150114 16:17:47 Percona XtraDB (http://www.percona.com) 5.5.35-33.0 started; log sequence number 1603244


[notice (again)]

  If you use binary log and don‘t use any hack of group commit,

  the binary log position seems to be:

InnoDB: Last MySQL binlog file position 0 2263, file name ./mysql-bin.000004


xtrabackup: starting shutdown with innodb_fast_shutdown = 1

150114 16:17:47  InnoDB: Starting shutdown...

150114 16:17:51  InnoDB: Shutdown completed; log sequence number 1604458


150114 16:17:51  innobackupex: Restarting xtrabackup with command: xtrabackup_55  --defaults-file="/tmp/restore/backup-my.cnf"  --defaults-group="mysqld" --prepare --target-dir=/tmp/restore --tmpdir=/tmp

for creating ib_logfile*


xtrabackup_55 version 2.1.9 for Percona Server 5.5.35 Linux (i686) (revision id: 744)

xtrabackup: cd to /tmp/restore

xtrabackup: This target seems to be already prepared.

xtrabackup: notice: xtrabackup_logfile was already used to ‘--prepare‘.

xtrabackup: using the following InnoDB configuration for recovery:

xtrabackup:   innodb_data_home_dir = ./

xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend

xtrabackup:   innodb_log_group_home_dir = ./

xtrabackup:   innodb_log_files_in_group = 2

xtrabackup:   innodb_log_file_size = 5242880

xtrabackup: using the following InnoDB configuration for recovery:

xtrabackup:   innodb_data_home_dir = ./

xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend

xtrabackup:   innodb_log_group_home_dir = ./

xtrabackup:   innodb_log_files_in_group = 2

xtrabackup:   innodb_log_file_size = 5242880

xtrabackup: Starting InnoDB instance for recovery.

xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)

150114 16:17:51 InnoDB: The InnoDB memory heap is disabled

150114 16:17:51 InnoDB: Mutexes and rw_locks use GCC atomic builtins

150114 16:17:51 InnoDB: Compressed tables use zlib 1.2.3

150114 16:17:51 InnoDB: Initializing buffer pool, size = 100.0M

150114 16:17:51 InnoDB: Completed initialization of buffer pool

150114 16:17:51  InnoDB: Log file ./ib_logfile0 did not exist: new to be created

InnoDB: Setting log file ./ib_logfile0 size to 5 MB

InnoDB: Database physically writes the file full: wait...

150114 16:17:51  InnoDB: Log file ./ib_logfile1 did not exist: new to be created

InnoDB: Setting log file ./ib_logfile1 size to 5 MB

InnoDB: Database physically writes the file full: wait...

150114 16:17:51 InnoDB: highest supported file format is Barracuda.

InnoDB: The log sequence number in ibdata files does not match

InnoDB: the log sequence number in the ib_logfiles!

150114 16:17:51  InnoDB: Database was not shut down normally!

InnoDB: Starting crash recovery.

InnoDB: Reading tablespace information from the .ibd files...

InnoDB: Last MySQL binlog file position 0 2263, file name ./mysql-bin.000004

150114 16:17:52  InnoDB: Waiting for the background threads to start

150114 16:17:53 Percona XtraDB (http://www.percona.com) 5.5.35-33.0 started; log sequence number 1604620


[notice (again)]

  If you use binary log and don‘t use any hack of group commit,

  the binary log position seems to be:

InnoDB: Last MySQL binlog file position 0 2263, file name ./mysql-bin.000004


xtrabackup: starting shutdown with innodb_fast_shutdown = 1

150114 16:17:53  InnoDB: Starting shutdown...

150114 16:17:57  InnoDB: Shutdown completed; log sequence number 1604620

150114 16:17:57  innobackupex: completed OK!

[root@centos64_1 data]# 

此时的目录结构如下:

[root@centos64_1 restore]# ll

total 30744

-rw-r--r-- 1 root root      260 Jan 14 15:50 backup-my.cnf

-rw-rw---- 1 root root 18874368 Jan 14 16:17 ibdata1

-rw-r--r-- 1 root root  5242880 Jan 14 16:17 ib_logfile0

-rw-r--r-- 1 root root  5242880 Jan 14 16:17 ib_logfile1

drwxr-xr-x 2 root root     4096 Jan 14 16:13 test

-rw-r--r-- 1 root root       13 Jan 14 15:50 xtrabackup_binary

-rw-r--r-- 1 root root       23 Jan 14 15:50 xtrabackup_binlog_info

-rw-r--r-- 1 root root       24 Jan 14 16:17 xtrabackup_binlog_pos_innodb

-rw-rw---- 1 root root       89 Jan 14 16:17 xtrabackup_checkpoints

-rw-rw---- 1 root root  2097152 Jan 14 16:17 xtrabackup_logfile

[root@centos64_1 restore]# 

这里的--apply-log指明是将日志应用到数据文件上,完成之后将备份文件中的数据恢复到数据库中。

把test目录复制到/opt/data/mysql目录 中:

[root@centos64_1 restore]# rsync -avz test ib* /opt/data/mysql/

然后再修改test的用户与组为mysql:

[root@centos64_1 mysql]# chown -R mysql:mysql test

[root@centos64_1 mysql]# chown mysql.mysql ib*

然后启动mysql,并查看test数据库的表里内容。

[root@centos64_1 mysql]# service mysqld start


mysql> use test;

Database changed

mysql> select * from test;

+------+

| id   |

+------+

|    1 |

|    2 |

|    3 |

|    4 |

|    5 |

+------+

5 rows in set (0.05 sec)

mysql> 

可以看到数据库已经恢复完成。

可能大家有个疑问,为什么我这里不像很多网上的文章里是在apply-log后,使用copy-back如果使用/usr/bin/innobackupex --copy-back命令后,会报Original data directory is not empty! at /usr/local/xtrabackup/bin/innobackupex line 538.恢复的目录必须为空。经查官网,这是xtrabackup的一个BUG。
innobackupex–copy-back was run. With this bug fix, innobackupex–copy-back operation if the destination is not empty, avoiding potential data loss or a strang combination of a restored backup and previous data. Bug Fixed: #737569 (Valentine Gostev) will now error out of the did not check that MySQL datadir was empty before
所以在apply-log后直接复制数据目录到数据库的位置上吧。

三、对数据库的增量备份与恢复

为了进行增量备份,先对数据库添加一些数据:

mysql> insert into test values(11);

mysql> insert into test values(12);

mysql> insert into test values(13);

mysql> insert into test values(14);

mysql> insert into test values(15);

mysql> flush privileges;

然后进行增量的备份:


[root@centos64 data]# innobackupex --user=root --password=root --database=test --incremental --incremental-basedir=/tmp/restore/ /tmp/data


InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy

and Percona LLC and/or its affiliates 2009-2013.  All Rights Reserved.


This software is published under

the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.


Get the latest version of Percona XtraBackup, documentation, and help resources:

http://www.percona.com/xb/p


150114 17:30:14  innobackupex: Connecting to MySQL server with DSN ‘dbi:mysql:;mysql_read_default_group=xtrabackup‘ as ‘root‘  (using password: YES).

150114 17:30:14  innobackupex: Connected to MySQL server

150114 17:30:14  innobackupex: Executing a version check against the server...

150114 17:30:14  innobackupex: Done.

IMPORTANT: Please check that the backup run completes successfully.

           At the end of a successful backup run innobackupex

           prints "completed OK!".


innobackupex: Using mysql server version 5.5.14-log


innobackupex: Created backup directory /tmp/data/2015-01-14_17-30-14


150114 17:30:14  innobackupex: Starting ibbackup with command: xtrabackup_55  --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/tmp/data/2015-01-14_17-30-14 --tmpdir=/tmp --incremental-basedir=‘/tmp/restore/‘

innobackupex: Waiting for ibbackup (pid=28406) to suspend

innobackupex: Suspend file ‘/tmp/data/2015-01-14_17-30-14/xtrabackup_suspended_2‘


xtrabackup_55 version 2.1.9 for Percona Server 5.5.35 Linux (i686) (revision id: 744)

incremental backup from 1603244 is enabled.

xtrabackup: uses posix_fadvise().

xtrabackup: cd to /opt/data/mysql

xtrabackup: open files limit requested 0, set to 1024

xtrabackup: using the following InnoDB configuration:

xtrabackup:   innodb_data_home_dir = ./

xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend

xtrabackup:   innodb_log_group_home_dir = ./

xtrabackup:   innodb_log_files_in_group = 2

xtrabackup:   innodb_log_file_size = 5242880

>> log scanned up to (1606817)

xtrabackup: using the full scan for incremental backup

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

>> log scanned up to (1606817)

[01] Copying ./ibdata1 to /tmp/data/2015-01-14_17-30-14/ibdata1.delta

>> log scanned up to (1606817)

[01]        ...done

>> log scanned up to (1606817)

xtrabackup: Creating suspend file ‘/tmp/data/2015-01-14_17-30-14/xtrabackup_suspended_2‘ with pid ‘28406‘


150114 17:30:41  innobackupex: Continuing after ibbackup has suspended

150114 17:30:41  innobackupex: Starting to lock all tables...

150114 17:30:41  innobackupex: All tables locked and flushed to disk


150114 17:30:41  innobackupex: Starting to backup non-InnoDB tables and files

innobackupex: in subdirectories of ‘/opt/data/mysql‘

innobackupex: Backing up file ‘/opt/data/mysql/test/test.frm‘

innobackupex: Backing up file ‘/opt/data/mysql/test/db.opt‘

150114 17:30:42  innobackupex: Finished backing up non-InnoDB tables and files


150114 17:30:42  innobackupex: Waiting for log copying to finish


xtrabackup: The latest check point (for incremental): ‘1606817‘

xtrabackup: Stopping log copying thread.

.>> log scanned up to (1606817)


xtrabackup: Creating suspend file ‘/tmp/data/2015-01-14_17-30-14/xtrabackup_log_copied‘ with pid ‘28406‘

xtrabackup: Transaction log of lsn (1606817) to (1606817) was copied.

150114 17:30:43  innobackupex: All tables unlocked


innobackupex: Backup created in directory ‘/tmp/data/2015-01-14_17-30-14‘

innobackupex: MySQL binlog position: filename ‘mysql-bin.000008‘, position 1111

150114 17:30:43  innobackupex: Connection to database server closed

150114 17:30:43  innobackupex: completed OK!

[root@centos64 data]# 

其中,--incremental指明是增量备份,--incremental-basedir指定上次完整备份或者增量备份文件的位置。这里的增量备份其实只针对的是InnoDB,对于MyISAM来说,还是完整备份。

在进行增量备份的恢复之前,先关闭数据库,然后删除数据库test。

[root@centos64 data]# service mysqld stop

[root@centos64_1 mysql]# rm -rf test/

增量备份的恢复:


[root@centos64 data]# innobackupex -user=root --password=root --defaults-file=/etc/my.cnf --apply-log /tmp/restore/ --incremental-dir=/tmp/data/2015-01-14_17-30-14/


InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy

and Percona LLC and/or its affiliates 2009-2013.  All Rights Reserved.


This software is published under

the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.


Get the latest version of Percona XtraBackup, documentation, and help resources:

http://www.percona.com/xb/p


IMPORTANT: Please check that the apply-log run completes successfully.

           At the end of a successful apply-log run innobackupex

           prints "completed OK!".


150114 17:36:54  innobackupex: Starting ibbackup with command: xtrabackup_55  --defaults-file="/etc/my.cnf"  --defaults-group="mysqld" --prepare --target-dir=/tmp/restore --incremental-dir=/tmp/data/2015-01-14_17-30-14/ --tmpdir=/tmp


xtrabackup_55 version 2.1.9 for Percona Server 5.5.35 Linux (i686) (revision id: 744)

incremental backup from 1603244 is enabled.

xtrabackup: cd to /tmp/restore

xtrabackup: This target seems to be already prepared.

xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(1606817)

xtrabackup: using the following InnoDB configuration for recovery:

xtrabackup:   innodb_data_home_dir = ./

xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend

xtrabackup:   innodb_log_group_home_dir = /tmp/data/2015-01-14_17-30-14/

xtrabackup:   innodb_log_files_in_group = 1

xtrabackup:   innodb_log_file_size = 2097152

xtrabackup: page size for /tmp/data/2015-01-14_17-30-14//ibdata1.delta is 16384 bytes

Applying /tmp/data/2015-01-14_17-30-14//ibdata1.delta to ././ibdata1...

xtrabackup: using the following InnoDB configuration for recovery:

xtrabackup:   innodb_data_home_dir = ./

xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend

xtrabackup:   innodb_log_group_home_dir = /tmp/data/2015-01-14_17-30-14/

xtrabackup:   innodb_log_files_in_group = 1

xtrabackup:   innodb_log_file_size = 2097152

xtrabackup: Starting InnoDB instance for recovery.

xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)

150114 17:36:54 InnoDB: The InnoDB memory heap is disabled

150114 17:36:54 InnoDB: Mutexes and rw_locks use GCC atomic builtins

150114 17:36:54 InnoDB: Compressed tables use zlib 1.2.3

150114 17:36:57 InnoDB: Initializing buffer pool, size = 100.0M

150114 17:36:59 InnoDB: Completed initialization of buffer pool

150114 17:36:59 InnoDB: highest supported file format is Barracuda.

InnoDB: The log sequence number in ibdata files does not match

InnoDB: the log sequence number in the ib_logfiles!

150114 17:36:59  InnoDB: Database was not shut down normally!

InnoDB: Starting crash recovery.

InnoDB: Reading tablespace information from the .ibd files...

InnoDB: Last MySQL binlog file position 0 1032, file name ./mysql-bin.000008

150114 17:37:02 Percona XtraDB (http://www.percona.com) 5.5.35-33.0 started; log sequence number 1606817


[notice (again)]

  If you use binary log and don‘t use any hack of group commit,

  the binary log position seems to be:

InnoDB: Last MySQL binlog file position 0 1032, file name ./mysql-bin.000008


xtrabackup: starting shutdown with innodb_fast_shutdown = 1

150114 17:37:02  InnoDB: Starting shutdown...

150114 17:37:07  InnoDB: Shutdown completed; log sequence number 1606817

innobackupex: Starting to copy non-InnoDB files in ‘/tmp/data/2015-01-14_17-30-14/‘

innobackupex: to the full backup directory ‘/tmp/restore‘

innobackupex: Copying ‘/tmp/data/2015-01-14_17-30-14/xtrabackup_binlog_info‘ to ‘/tmp/restore/xtrabackup_binlog_info‘

innobackupex: Copying ‘/tmp/data/2015-01-14_17-30-14/test/test.frm‘ to ‘/tmp/restore/test/test.frm‘

innobackupex: Copying ‘/tmp/data/2015-01-14_17-30-14/test/db.opt‘ to ‘/tmp/restore/test/db.opt‘

150114 17:37:07  innobackupex: completed OK!

[root@centos64 data]# 

然后再进入恢复的目录/tmp/data,跟全部备份一样,把test恢复到/opt/data/mysql里:

[root@centos64 2015-01-14_17-30-14]# rsync -avz test ib* /opt/data/mysql/

sending incremental file list

ibdata1.delta

ibdata1.meta

test/

test/db.opt

test/test.frm

sent 5454 bytes  received 92 bytes  11092.00 bytes/sec

total size is 385493  speedup is 69.51

[root@centos64 2015-01-14_17-30-14]# 

[root@centos64_1 mysql]# chown -R mysql:mysql test/ ib*

然后启动msyql,并查看test数据库里test表的内容:

[root@centos64_1 mysql]# service mysqld start

mysql> use test;

Database changed

mysql> select * from test;

+------+

| id   |

+------+

|    1 |

|    2 |

|    3 |

|    4 |

|    5 |

|   11 |

|   12 |

|   13 |

|   14 |

|   15 |

+------+

10 rows in set (0.00 sec)

至此增量备份已经恢复完成。

xtrabackup备份与恢复MySQL

标签:xtrabackup

原文地址:http://xiaoze.blog.51cto.com/245749/1603771

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!