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

xtrabackup增量备份方案,备份恢复全过程记录
mysql> select * from mm;
+------+
| a    |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
+------+
4 rows in set (0.00 sec)

mysql> show tables;
+----------------+
| Tables_in_inno |
+----------------+
| mm             |
| t              |
+----------------+
2 rows in set (0.01 sec)

mysql> insert into mm select 9999;
Query OK, 1 row affected (0.01 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into t select 9999;
Query OK, 1 row affected (0.16 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql>
mysql> select * from t;
+------+
| a    |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

mysql> select * from mm;
+------+
| a    |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
| 9999 |
+------+
5 rows in set (0.00 sec)

mysql> select * from t;
+------+
| a    |
+------+
|    1 |
|    2 |
|    3 |
| 9999 |
+------+
4 rows in set (0.00 sec)

mysql> 

以上是准备相关的环境,以下开始进行备份恢复相关的记录;

增量备份及模拟恢复步骤:
先做一次全量备份,增量备份需要以此为基础 
[root@Slave02 inno]# mkdir -p /data/back_up/delta    ---建立增量备份文件夹
[root@Slave02 inno]# cd /data/back_up/
[root@Slave02 back_up]# ls
delta  ibdata1  inno  xtrabackup_checkpoints  xtrabackup_logfile
[root@Slave02 back_up]# cd delta/
[root@Slave02 delta]# ls
[root@Slave02 delta]# 
[root@Slave02 delta]# ls -la
total 16
drwxr-xr-x 2 root root 4096 Mar 27 14:35 .
drwxr-xr-x 4 root root 4096 Mar 27 14:35 ..
[root@Slave02 delta]# 
[root@Slave02 delta]# xtrabackup_55 --defaults-file=/etc/my.cnf  --backup  --tar
get-dir=/data/back_up/delta  --incremental-basedir=/data/back_up     
xtrabackup_55 version 1.6.2 for MySQL server 5.5.10 Linux (i686) (revision id: undefined)
incremental backup from 893330211 is enabled.
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /usr/local/mysql/data
xtrabackup: Target instance is assumed 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 = 2
xtrabackup:   innodb_log_file_size = 5242880
130327 14:38:04 InnoDB: Using Linux native AIO
130327 14:38:04  InnoDB: Warning: allocated tablespace 2, old maximum was 0
>> log scanned up to (893330821)
[01] Copying ./ibdata1 
     to /data/back_up/delta/ibdata1.delta
[01]        ...done
[01] Copying ./inno/mm.ibd 
     to /data/back_up/delta/inno/mm.ibd.delta
[01]        ...done
[01] Copying ./inno/t.ibd 
     to /data/back_up/delta/inno/t.ibd.delta
[01]        ...done
>> log scanned up to (893330821)
xtrabackup: The latest check point (for incremental): '893330821'
>> log scanned up to (893330821)
xtrabackup: Stopping log copying thread.
xtrabackup: Transaction log of lsn (893330821) to (893330821) was copied.
[root@Slave02 delta]# 
[root@Slave02 delta]# ls /data/back_up/delta/    -生成的增量备份数据文件
ibdata1.delta  ibdata1.meta  inno  xtrabackup_checkpoints  xtrabackup_logfile
[root@Slave02 delta]# 
[root@Slave02 delta]# cd inno/
[root@Slave02 inno]# ls
mm.ibd.delta  mm.ibd.meta  t.ibd.delta  t.ibd.meta
[root@Slave02 inno]# ll
total 88
-rw-r--r-- 1 root root 32768 Mar 27 14:38 mm.ibd.delta
-rw-r--r-- 1 root root    18 Mar 27 14:38 mm.ibd.meta
-rw-r--r-- 1 root root 32768 Mar 27 14:38 t.ibd.delta
-rw-r--r-- 1 root root    18 Mar 27 14:38 t.ibd.meta
[root@Slave02 inno]#
注:在增量备份目录下,数据文件都是以.delta结尾的。增量备份只备份上一次全量备份后被修改过的page,所以增量备份只暂用较少的空 间。增量备份可以在增量备份的基础上增量。增量备份目录每次都需修改的。比如第二次增量就改成/data/back_up/delta2/) 
备份恢复过程,对增量和全量各种一次prepare即可;
全量的prepare;
[root@Slave02 delta]# xtrabackup_55 --defaults-file=/etc/my.cnf  --prepare  --target-dir=/data/back_up
xtrabackup_55 version 1.6.2 for MySQL server 5.5.10 Linux (i686) (revision id: undefined)
xtrabackup: cd to /data/back_up
xtrabackup: This target seems to be not prepared yet.
xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(893330211)
xtrabackup: Temporary instance for recovery is s