Mysql学习之XtraBackup(2)-------增量备份与恢复

增量备份

先做一次全量备份:

innobackupex --defaults-file=/etc/my.cnf -ubkpuser -pxxx --no-timestamp /u01/mysqlbackup/all-20190729bak
...
...
190727 14:35:57 completed OK!

or

xtrabackup --defaults-file=/etc/my.cnf  -ubkpuser -pxxx --backup --target-dir=/u01/mysqlbackup/all-20190729bak
...
190727 21:13:12 completed OK!

 

在全量备份的基础上做一次增量备份:

innobackupex --defaults-file=/etc/my.cnf -ubkpuser -pxxx --no-timestamp --incremental /u01/mysqlbackup/inc-2019072901bak --incremental-basedir=/u01/mysqlbackup/all-20190729bak
...
incremental backup from 235566786 is enabled.
...
190727 15:18:17 completed OK!

or

xtrabackup --defaults-file=/etc/my.cnf  -ubkpuser -pxxx --backup --target-dir=/u01/mysqlbackup/inc-20190729bak --incremental-basedir=/u01/mysqlbackup/all-20190729bak
...
incremental backup from 235568424 is enabled.
...
190727 21:18:10 completed OK!

 

再做一次增量备份:

innobackupex --defaults-file=/etc/my.cnf -ubkpuser -pxxx --no-timestamp --incremental /u01/mysqlbackup/inc-2019072902bak --incremental-basedir=/u01/mysqlbackup/inc-2019072901bak
...
incremental backup from 235567145 is enabled.
...
190727 15:33:25 completed OK!

or 

xtrabackup --defaults-file=/etc/my.cnf  -ubkpuser -pxxx --backup --target-dir=/u01/mysqlbackup/inc-2019072902bak --incremental-basedir=/u01/mysqlbackup/inc-20190729bak
...
incremental backup from 235568424 is enabled.
...
190727 21:21:55 completed OK!


查看两次增量备份文件的xtrabackup_checkpoints文件,可以发现他们的lsn是连续的:

[root@rhel6 all-20190729bak]# cat xtrabackup_checkpoints 
backup_type = full-backuped
from_lsn = 0
to_lsn = 235566786
last_lsn = 235566795
compact = 0
recover_binlog_info = 0
flushed_lsn = 235566795
[root@rhel6 all-20190729bak]# cat ../inc-2019072901bak/xtrabackup_checkpoints 
backup_type = incremental
from_lsn = 235566786
to_lsn = 235567145
last_lsn = 235567154
compact = 0
recover_binlog_info = 0
flushed_lsn = 235567154
[root@rhel6 all-20190729bak]# cat ../inc-2019072902bak/xtrabackup_checkpoints 
backup_type = incremental
from_lsn = 235567145
to_lsn = 235567464
last_lsn = 235567473
compact = 0
recover_binlog_info = 0
flushed_lsn = 235567473

 

增量备份恢复

prepare过程 :
先对全量备份进行prepare,注意使用innobackupex时要使用--redo-only参数

innobackupex -ubkpuser -pxxx --apply-log --redo-only /u01/mysqlbackup/all-20190729bak
...
190727 17:01:48 completed OK!

or

xtrabackup --prepare --apply-log-only /u01/mysqlbackup/all-20190729bak
...
190727 21:26:51 completed OK!


然后把增量备份1恢复到全量备份文件中 

innobackupex -ubkpuser -pxxx --apply-log --redo-only /u01/mysqlbackup/all-20190729bak --incremental-dir=/u01/mysqlbackup/inc-2019072901bak
...
incremental backup from 235566786 is enabled.
...
190727 17:43:44 completed OK!

or

xtrabackup --prepare --apply-log-only --target-dir=/u01/mysqlbackup/all-20190729bak --incremental-dir=/u01/mysqlbackup/inc-20190729bak
...
incremental backup from 235568424 is enabled.
...
190727 21:28:30 completed OK!

 
再把增量备份2恢复到全量备份文件中  

innobackupex -ubkpuser -xxx --apply-log --redo-only /u01/mysqlbackup/all-20190729bak --incremental-dir=/u01/mysqlbackup/inc-2019072902bak
...
incremental backup from 235567145 is enabled.
...
190727 17:43:44 completed OK!

or 

xtrabackup --prepare --apply-log-only --target-dir=/u01/mysqlbackup/all-20190729bak --incremental-dir=/u01/mysqlbackup/inc-2019072902bak
...
incremental backup from 235568424 is enabled.
...
190727 21:30:40 completed OK!


最后再对全量备份文件进行apply log

innobackupex --ubkpuser -xxx --apply-log /u01/mysqlbackup/all-20190729bak

or

xtrabackup --prepare  --target-dir=/u01/mysqlbackup/all-20190729bak

 
恢复过程:
       1)停Mysql--------service mysql stop
       2)备份data文件夹--------mv /u01/mysql/data  /u01/mysql/data_bak0729
       3)把已经prepare的全量备份copy过来--------cp -R /u01/mysqlbackup/all-20190729bak  /u01/mysql/data
       4)修改文件夹及子文件权限--------chown -R mysql:mysql /u01/mysql/data
       5)起Mysql--------service mysql start
 

 

 

你可能感兴趣的:(Mysql)