标签:恢复备份 操作 bsp table mysqld 相同 res https commit
#下载epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#安装依赖
yum -y install perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL
#下载Xtrabackup
备份方式(是物理备份可以理解为拷贝数据文件,深层理解是备份数据页)
#全备
[root@db01 data]# innobackupex --user=root --password=123 /backup
#避免时间戳,自定义路径名
[root@db01 ~]# innobackupex --user=root --password=123 --no-timestamp /backup/full
#查看备份路径中的内容
[root@db01 backup]# ll /backup/full
#记录binlog文件名和binlog的位置点
-rw-r----- 1 root root 21 Aug 16 06:23 xtrabackup_binlog_info
#备份时刻,立即将已经commit过的内存中的数据页刷新到磁盘
#备份时刻有可能会有其他数据写入,已备走的数据文件就不会再发生变化了
#在备份过程中,备份软件会一直监控着redo和undo,一旦有变化会将日志一并备走
-rw-r----- 1 root root 117 Aug 16 06:23 xtrabackup_checkpoints
#备份汇总信息
-rw-r----- 1 root root 485 Aug 16 06:23 xtrabackup_info
#备份的redo文件
-rw-r----- 1 root root 2560 Aug 16 06:23 xtrabackup_logfile
innobackupex --user=root --password=123 --no-timestamp /backup/full
前提1:被恢复的目录是空的
前提2:被恢复的数据库的实例是关闭的
将redo进行重做,已提交的写到数据文件,未提交的使用undo回滚,模拟CSR的过程
[root@db01 full]# innobackupex --user=root --password=123 --apply-log /backup/full
[root@db01 mysql]# innobackupex --copy-back /backup/full
[root@db01 mysql]# chown -R mysql.mysql /application/mysql/data/
[root@db01 mysql]# /etc/init.d/mysqld start
[root@db01 backup]#innobackupex --user=root --password=123 --no-timestamp /bakcup/full
所有的全备增量备份之间,都要有联系的,都能组合到一起,必须是严丝合缝的一个号不能差
[root@db01 ~]#cat /backup/full/xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0 #全备from_lsn都是从0开始
to_lsn = 649294557 #只要有数据变化这个号就会变 有了64.....个操作
last_lsn = 649294557
compact = 0
recover_binlog_info = 0
mysql> use world;
mysql> create table city1 select * from city;
参数说明:
--incremental:打开增量备份开关
--incremental-basedir:基于哪次备份,进行增量备份 写上一次备份的路径就行
[root@db01 ~]#innobackupex --user=root --password=oldboy123 --no-timestamp --incremental --incremental-basedir=/backup/full /backup/inc1
[root@db01 ~]#cat /backup/full/xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0
to_lsn = 788066534
last_lsn = 788066534
compact = 0
recover_binlog_info = 0
[root@db01 ~]#cat /backup/inc1/xtrabackup_checkpoints
backup_type = incremental
from_lsn = 788066534
to_lsn = 788625806
last_lsn = 788625806
compact = 0
recover_binlog_info = 0
mysql> use world;
mysql> create table city2 select * from city;
[root@db01 ~]#innobackupex --user=root --password=oldboy123 --no-timestamp --incremental --incremental-basedir=/backup/inc1 /backup/inc2
[root@db01 ~]#cat /backup/full/xtrabackup_checkpoints /backup/inc1/xtrabackup_checkpoints /b
ackup/inc2//xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0
to_lsn = 788066534
last_lsn = 788066534
compact = 0
recover_binlog_info = 0
--------------------------------------------------------------
backup_type = incremental
from_lsn = 788066534
to_lsn = 788625806
last_lsn = 788625806
compact = 0
recover_binlog_info = 0
--------------------------------------------------------------
backup_type = incremental
from_lsn = 788625806
to_lsn = 789184862
last_lsn = 789184862
compact = 0
recover_binlog_info = 0
把data目录全删除
[root@db01 ~]# rm -fr /application/mysql/data/*
[root@db01 data]#pkill mysqld
注意事项:
1 增量备份是不能直接恢复使用,必须要把所有增量合并到同一个全备中,最后进行一次恢复,会读ch文件自动的接到一起, 才能恢复增量(不像别的产品,恢复增量要依次恢复增量),
2 在合并过程中,顺便进行备份的准备,(apply-log),在准备过程中,只有最后一次合并增量redo和undo都应用,中间合并过程只应用redo,只进行前滚,不做回滚,防止lsn号接不上
[root@db01 ~]# innobackupex --apply-log --redo-only /backup/full/
--incremental-dir=/backup/inc1 --incremental-dir 指定要合并的增量备份路径
[root@db01 ~]#innobackupex --user=root --password=oldboy123 --apply-log --redo-only --incremental-dir=/backup/inc1 /backup/full
查看lsn full的last_lsn的值= inc1 last_lsn的值,证明 全量备份中已经包含了inc1了
[root@db01 ~]#cat /backup/full/xtrabackup_checkpoints
backup_type = log-applied
from_lsn = 0
to_lsn = 788625806
last_lsn = 788625806
compact = 0
recover_binlog_info = 0
[root@db01 ~]#cat /backup/inc1/xtrabackup_checkpoints
backup_type = incremental
from_lsn = 788066534
to_lsn = 788625806
last_lsn = 788625806
compact = 0
recover_binlog_info = 0
[root@db01 ~]#innobackupex --apply-log --incremental-dir=/backup/inc2 /backup/full
inc2 的laset_lsn号和full的号相同,证明合并成功,
[root@db01 ~]#cat /backup/inc2/xtrabackup_checkpoints /backup/full/xtrabackup_checkpoints
backup_type = incremental
from_lsn = 788625806
to_lsn = 789184862
last_lsn = 789184862
compact = 0
recover_binlog_info = 0
backup_type = full-prepared
from_lsn = 0
to_lsn = 789184862
last_lsn = 789184862
compact = 0
recover_binlog_info = 0
整体full执行apply-log,redo和undo都应用
[root@db01 mysql]# innobackupex --apply-log /backup/full/
[root@db01 ~]# innobackupex --copy-back /backup/full/
[root@db01 ~]# chown -R mysql.mysql /application/mysql/data/
[root@db01 ~]# /etc/init.d/mysqld start
标签:恢复备份 操作 bsp table mysqld 相同 res https commit
原文地址:https://www.cnblogs.com/john5yang/p/10480278.html