XTRABACKUP原理分析

XTRABACKUP在启动的时候会记录一个LSN(LOGSEQUENCE NUMBER), 然后就把所有的INNODB数据文件复制出来,这样复制出来的数据文件是不一致的, 
但是XTRABACKUP会在后台运行一个进程把所有对REDO LOG FILE的修改记录下来, 只要有了这个数据, 就能进行崩溃恢复。只所以要额外
记录下来, 是因为MYSQL自身的REDO LOG FILE是可重用的。 
如果用INNOBACKUPEX脚本, 刚才的步骤完成以后, INNOBACKUPEX就会去备份MYISAM表和.FRM文件, 这时要保证数据的一致性就会锁表了,
通过FLUSH TABLES WITHREAD LOCK命令锁表然后把文件复制出来, 再释放放掉这个锁。
在恢复数据的时候, 要经过PREPARE(RECOVER)和RESTORE这两步。 在PREPARE结束以后, INNODB的表恢复到了复制INNODB文件结束的时间点,
这个时间点也就是锁表复制MYISAM表的起点,所以最终数据是一致的。 一般我们在恢复的时候执行两次PREPARE, 是因为第二次PREPARE会帮助
我们生成REDO LOG文件, 从而加快MYSQL数据库启动的速度。
下面我们来分析一下备份的过程:

[root@localhost ~]# /u01/percona-xtrabackup-2.0.2/bin/innobackupex --user=root --password=vipshop --socket=/tmp/mysql3306.sock --defaults-file=/etc/my.cnf /u01/

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.

140425 15:45:43 innobackupex: Starting mysql with options: --defaults-file='/etc/my.cnf' --password=xxxxxxxx --user='root' --socket='/tmp/mysql3306.sock' --unbuffered --
140425 15:45:43 innobackupex: Connected to database with mysql child process (pid=9100)
140425 15:45:49 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.14 Distrib 5.5.30, for Linux (x86_64) using EditLine wrapper
innobackupex: Using mysql server version Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Warning: xtrabackup_55: ignoring option '--innodb_adaptive_hash_index' due to invalid value 'ON'
innobackupex: Created backup directory /u01/2014-04-25_15-45-49
140425 15:45:49 innobackupex: Starting mysql with options: --defaults-file='/etc/my.cnf' --password=xxxxxxxx --user='root' --socket='/tmp/mysql3306.sock' --unbuffered --
140425 15:45:49 innobackupex: Connected to database with mysql child process (pid=9127)
140425 15:45:51 innobackupex: Connection to database server closed

140425 15:45:51 innobackupex: Starting ibbackup with command: xtrabackup_55 --defaults-file="/etc/my.cnf" --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/u01/2014-04-25_15-45-49
innobackupex: Waiting for ibbackup (pid=9134) to suspend
innobackupex: Suspend file '/u01/2014-04-25_15-45-49/xtrabackup_suspended'

Warning: xtrabackup_55: ignoring option '--innodb_adaptive_hash_index' due to invalid value 'ON'
xtrabackup_55 version 2.0.2 for Percona Server 5.5.16 Linux (x86_64) (revision id: undefined)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /u01/mysql/data
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = /u01/mysql/data
xtrabackup: innodb_data_file_path = ibdata1:1000M:autoextend
xtrabackup: innodb_log_group_home_dir = /u01/mysql/data
xtrabackup: innodb_log_files_in_group = 4
xtrabackup: innodb_log_file_size = 1048576000
140425 15:45:51 InnoDB: Using Linux native AIO
xtrabackup: using O_DIRECT
>> log scanned up to (1595669)  ----获取LSN
[01] Copying /u01/mysql/data/ibdata1 to /u01/2014-04-25_15-45-49/ibdata1   ---COPY数据文件
>> log scanned up to (1595669)
[01] ...done

140425 15:45:59 innobackupex: Continuing after ibbackup has suspended
140425 15:45:59 innobackupex: Starting mysql with options: --defaults-file='/etc/my.cnf' --password=xxxxxxxx --user='root' --socket='/tmp/mysql3306.sock' --unbuffered --
140425 15:45:59 innobackupex: Connected to database with mysql child process (pid=9152)
140425 15:46:01 innobackupex: Starting to lock all tables...  ---开始获取所有表的锁
>> log scanned up to (1595669)
>> log scanned up to (1595669)
140425 15:46:11 innobackupex: All tables locked and flushed to disk

140425 15:46:11 innobackupex: Starting to backup .frm, .MRG, .MYD, .MYI,   ---开始备份.FRM等文件。
innobackupex: .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV and .opt files in
innobackupex: subdirectories of '/u01/mysql/data'
innobackupex: Backing up files '/u01/mysql/data/mysql/*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (72 files)
>> log scanned up to (1595669)
innobackupex: Backing up files '/u01/mysql/data/performance_schema/*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (18 files)
140425 15:46:11 innobackupex: Finished backing up .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSV, .CSM and .opt files

innobackupex: Resuming ibbackup

xtrabackup: The latest check point (for incremental): '1595669'     ---因为我这里是测试库, 如果是生产库的话, 这里应该是COPY REDO LOG。
xtrabackup: Stopping log copying thread.
.>> log scanned up to (1595669)

xtrabackup: Transaction log of lsn (1595669) to (1595669) was copied.
140425 15:46:14 innobackupex: All tables unlocked
140425 15:46:14 innobackupex: Connection to database server closed

innobackupex: Backup created in directory '/u01/2014-04-25_15-45-49'
innobackupex: MySQL binlog position: filename 'mysql-bin.000006', position 107
140425 15:46:14 innobackupex: completed OK!

  

posted @ 2014-06-04 16:40 SMALL-D 阅读(...) 评论(...)  编辑 收藏