xtrabackup: xtrabackup_logfile detected:> xtrabackup: Temporary instance for recovery is set as followings.
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)
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Warning: innodb_file_io_threads is deprecated. Please use innodb_read_io_threads and innodb_write_io_threads instead
110411 16:49:25 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 732446480
110411 16:49:25 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Doing recovery: scanned up to log sequence number 733504186 (56 %)
110411 16:49:25 InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
InnoDB: Last MySQL binlog file position 0 560768957, file name ./mysql-bin.000001
110411 16:49:25 Percona XtraDB (http://www.percona.com) 1.0.13-12.4 started; log sequence number 733504186
[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 560768957, file name ./mysql-bin.000001
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
110411 16:49:32 InnoDB: Starting shutdown...
110411 16:49:33 InnoDB: Shutdown completed; log sequence number 733553275
# ls
cacti ibdata1 nagios test xtrabackup_binlog_pos_innodb xtrabackup_checkpoints xtrabackup_logfile
# ./xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/mydata/mybak/
./xtrabackup Ver 1.5 Rev undefined for 5.1.53 unknown-linux-gnu (x86_64)
xtrabackup: cd to /mydata/mybak/
xtrabackup: This target seems to be already prepared.
xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.
xtrabackup: Temporary instance for recovery is set as followings.
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 = 3
xtrabackup: innodb_log_file_size = 268435456
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Warning: innodb_file_io_threads is deprecated. Please use innodb_read_io_threads and innodb_write_io_threads instead
110411 16:49:58 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0> InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200
110411 16:50:03 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1> InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200
110411 16:50:09 InnoDB: Log file ./ib_logfile2 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile2> InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200
110411 16:50:14 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!
110411 16:50:14 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 560768957, file name ./mysql-bin.000001
110411 16:50:14 Percona XtraDB (http://www.percona.com) 1.0.13-12.4 started; log sequence number 733553676
[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 560768957, file name ./mysql-bin.000001
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
110411 16:50:16 InnoDB: Starting shutdown...
110411 16:50:16 InnoDB: Shutdown completed; log sequence number 733553676
# ls
cacti ib_logfile0 ib_logfile2 test xtrabackup_checkpoints
ibdata1 ib_logfile1 nagios xtrabackup_binlog_pos_innodb xtrabackup_logfile
此时InnoDB的全部数据文件已经恢复了。将这些文件拷贝到datadir目录下。
注意:xtrabackup只是备份数据文件,不会备份数据表结构。因此恢复时,必须有对应的表结构文件。
# cp -r cacti /mydata/data/
# cp -r ib* /mydata/data/
# cp -r nagios /mydata/data/
# chown –R mysql.mysql /mydata/data
# /usr/local/mysql-5.5.11/bin/mysqld --user=mysql &
8.增量备份
a.全量备份
# ./xtrabackup --backup --target-dir=/mydata/mybak/base
xtrabackup: The latest check point (for incremental): '783599510'
>> log scanned up to (783977887)
xtrabackup: Stopping log copying thread.
xtrabackup: Transaction log of lsn (783374191) to (783977887) was copied.
# ls
cacti ibdata1 nagios xtrabackup_checkpoints xtrabackup_logfile
# cat xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0
to_lsn = 783599510
last_lsn = 783977887
b.增量备份
# ./xtrabackup --backup --target-dir=/mydata/mybak/delta --incremental-basedir=/mydata/mybak/base
incremental backup from 783599510 is enabled.
……
xtrabackup: The latest check point (for incremental): '793114541'
>> log scanned up to (795499255)
xtrabackup: Stopping log copying thread.
xtrabackup: Transaction log of lsn (793069999) to (795499255) was copied.
# ls /mydata/mybak/delta/
cacti ibdata1.delta nagios xtrabackup_checkpoints xtrabackup_logfile
# cat /mydata/mybak/delta/xtrabackup_checkpoints
backup_type = incremental
from_lsn = 783599510
to_lsn = 793114541
last_lsn = 795499255
在增量备份目录下,数据文件都是以.delta结尾的。增量备份只备份上一次全量备份之后被修改过的page。
C.恢复过程:需要分别对全量和增量备份进行恢复操作
# ./xtrabackup --prepare --target-dir=/mydata/mybak/base
# ./xtrabackup --prepare --target-dir=/mydata/mybak/base --incremental-dir=/mydata/mybak/delta
上述过程,首先将全部文件备份到/mydata/mybak/base目录下,增量备份产生的文件备份到/mydata/mybak/delta目录下。在恢复过程中,首先指定全量备份的路径,然后将增量备份应用于该全量备份。
将/mydata/mybak/base目录下的文件拷贝到datadir目录下,即可。同时还需要数据表结构文件。