innobackupex基于binlog日志的恢复 -- 使用mysqlbinlog恢复
备份
先做一次完整备份:
innobackupex --defaults-file=/etc/my.cnf --user root --password chengce243 /data/mysqlbak
执行完命令后,/data/mysqlbak 目录下会生成目录: 2018-08-06_14-19-12
记下操作后的 position 点
mysql> show master status;
+----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------+----------+--------------+------------------+-------------------+
| restoredb-bin.000001 | 154 | | | |
+----------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
多切换几次 binlog日志
mysql> flush logs;
[root@restoredb ~]# ll /data/mysql/*bin*
-rw-r----- 1 mysql mysql 205 Aug 6 14:26 /data/mysql/restoredb-bin.000001
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000002
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000003
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000004
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000005
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000006
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000007
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000008
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000009
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000010
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000011
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000012
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000013
-rw-r----- 1 mysql mysql 154 Aug 6 15:09 /data/mysql/restoredb-bin.000014
-rw-r----- 1 mysql mysql 322 Aug 6 15:09 /data/mysql/restoredb-bin.index
mysql> show master status;
+----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------+----------+--------------+------------------+-------------------+
| restoredb-bin.000014 | 154 | | | |
+----------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
插入测试数据
insert into testtab values (20001,'full_bak');
多切换几次 binlog日志
mysql> flush logs;
再插入测试数据
insert into testtab values (20002,'full_bak2');
[root@restoredb ~]# ll /data/mysql/*bin*
-rw-r----- 1 mysql mysql 205 Aug 6 14:26 /data/mysql/restoredb-bin.000001
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000002
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000003
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000004
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000005
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000006
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000007
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000008
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000009
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000010
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000011
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000012
-rw-r----- 1 mysql mysql 205 Aug 6 15:09 /data/mysql/restoredb-bin.000013
-rw-r----- 1 mysql mysql 479 Aug 6 15:13 /data/mysql/restoredb-bin.000014
-rw-r----- 1 mysql mysql 205 Aug 6 15:13 /data/mysql/restoredb-bin.000015
-rw-r----- 1 mysql mysql 205 Aug 6 15:13 /data/mysql/restoredb-bin.000016
-rw-r----- 1 mysql mysql 205 Aug 6 15:13 /data/mysql/restoredb-bin.000017
-rw-r----- 1 mysql mysql 429 Aug 6 15:14 /data/mysql/restoredb-bin.000018
-rw-r----- 1 mysql mysql 414 Aug 6 15:13 /data/mysql/restoredb-bin.index
再插入测试数据
insert into testtab values (20003,'full_bak3');
停止MySQL服务并清空数据目录:
/etc/init.d/mysqld stop
备份binlog(正常情况下,这些binlog会备份到binlog server,此处用复制模拟binlog server备份路径)。
[root@restoredb mysql]# cp *bin* /data/mysqlbak/binlogbak/
[root@restoredb mysql]# ll /data/mysqlbak/binlogbak/
total 76
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000001
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000002
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000003
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000004
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000005
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000006
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000007
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000008
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000009
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000010
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000011
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000012
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000013
-rw-r----- 1 root root 479 Aug 6 15:19 restoredb-bin.000014
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000015
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000016
-rw-r----- 1 root root 205 Aug 6 15:19 restoredb-bin.000017
-rw-r----- 1 root root 727 Aug 6 15:19 restoredb-bin.000018
-rw-r----- 1 root root 414 Aug 6 15:19 restoredb-bin.index
清空数据文件
rm -rf /data/mysql/*
恢复
直接复制 /data/mysqlbak/2018-08-06_14-19-12 目录下文件到 /data/mysql 目录下,然后修改权限
cp -r /data/mysqlbak/2018-08-06_14-19-12/* /data/mysql/
chown -R mysql:mysql /data/mysql
直接启动数据
/etc/init.d/mysqld start
查看此时的testtab表:
mysql> select *from testtab;
+-------+-----------+
| id | name |
+-------+-----------+
| 10000 | test |
| 10001 | incr_bak |
| 10002 | incr_bak2 |
+-------+-----------+
mysql> show master status;
+----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------+----------+--------------+------------------+-------------------+
| restoredb-bin.000001 | 154 | | | |
+----------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
测试数据 (20001,'full_bak')并不存在,说明binlog日志的数据并没有恢复
开始恢复binlog日志
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000001 --start-position=154 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000002 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000003 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000004 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000005 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000006 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000007 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000008 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000009 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000010 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000011 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000012 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000013 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000014 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000015 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000016 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000017 |mysql -u root -pchengce243
mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000018 |mysql -u root -pchengce243
查看数据
mysql> select *from testtab;
+-------+-----------+
| id | name |
+-------+-----------+
| 10000 | test |
| 10001 | incr_bak |
| 10002 | incr_bak2 |
| 20001 | full_bak |
| 20002 | full_bak2 |
| 20003 | full_bak3 |
+-------+-----------+
6 rows in set (0.01 sec)
发现已经是最新的数据,已经恢复过来。
innobackupex基于binlog日志的恢复 -- 使用mysqlbinlog恢复的更多相关文章
- innobackupex基于binlog日志的恢复 -- 模拟slave恢复
说明:一般来说,如果恢复的binlog量不大,可以使用此方法来恢复:mysqlbinlog /data/mysqlbak/binlogbak/restoredb-bin.000018 |mysql - ...
- mysql之 innobackupex备份+binlog日志的完全恢复【转】
前言: MySQL的完全恢复,我们可以借助于完整的 备份+binlog 来将数据库恢复到故障点. 备份可以是热备与逻辑备份(mysqldump),只要备份与binlog是完整的,都可以实现完全恢复. ...
- mysql之 innobackupex备份+binlog日志的完全恢复(命令行执行模式)
前言:MySQL的完全恢复,我们可以借助于完整的 备份+binlog 来将数据库恢复到故障点.备份可以是热备与逻辑备份(mysqldump),只要备份与binlog是完整的,都可以实现完全恢复. 1. ...
- mysql通过binlog日志来恢复数据
简介 在生产的过程中有这么一个业务场景:比如我在2016-11-19 09:30:00 通过mysqldump的方式备份了数据库,但是在2016-11-19 10:30:00的时候数据库崩溃了,如果通 ...
- 使用全备+binlog日志恢复数据库
1.binlog日志类型 Statement 只记录执行的sql语句,磁盘占用少,但是恢复的时候容易出问题.InodeDB不能使用Statement . Row 记录修改后的具体数据,磁盘占用较多 M ...
- 实战演习:mysqlbinlog恢复bin-log数据
mysqlbinlog恢复bin-log数据 Binlog日志即binary log,是二进制日志文件,有两个作用,一个是增量备份,另一个是主从复制,即从节点同步主节点数据时获取的即是bin-log, ...
- (4.11)mysql备份还原——mysql闪回技术(基于binlog)
0.闪回技术与工具简介 mysql闪回工具比较流行三大类: [0.1]官方的mysqlbinlog:支持数据库在线/离线,用脚本处理binlog的输出,转化成对应SQL再执行.通用性不好,对正则.se ...
- MySQL binlog日志三种模式选择及配置
在认识binlog日志三种模式前,先了解一下解析binlog日志的命令工mysqlbinlog.mysqlbinlog工具的作用是解析mysql的二进制binlog日志内容,把二进制日志解析成可以在M ...
- (转)Mysql数据库之Binlog日志使用总结
使用mysqlbinlog提取二进制日志 原文:http://blog.csdn.net/leshami/article/details/41962243 MySQL binlog日志记录了MySQL ...
随机推荐
- Environment Perception: 3D Truss Environment Mapping and Parametric Expression Extraction
Experiments Preparation roscore rosrun pcl_ros pcd_to_pointcloud ~/.ros/wh2_lg707070_1ms0.01_filtere ...
- java 提取(解压)zip文件中特定后缀的文件并保存到指定目录
内容简介 本文主要介绍使用ZipFile来提取zip压缩文件中特定后缀(如:png,jpg)的文件并保存到指定目录下. 导入包:import java.util.zip.ZipFile; 如需添加对r ...
- Exception异常处理
1.java异常类: 都是Throwable的子类: 1.Exception(异常) :是程序本身可以处理的异常. 2.Error(错误): 是程序无法处理的错误.这些错误表示故障发生于虚拟机自身.或 ...
- poj 1741 Tree(树的点分治)
poj 1741 Tree(树的点分治) 给出一个n个结点的树和一个整数k,问有多少个距离不超过k的点对. 首先对于一个树中的点对,要么经过根结点,要么不经过.所以我们可以把经过根节点的符合点对统计出 ...
- sg函数和nim游戏的关系
sg函数和nim游戏的关系 本人萌新,文章如有错漏请多多指教-- 我在前面发了关于nim游戏的内容,也就是说给n堆个数不同的石子,每次在某个堆中取任意个数石子,不能取了就输了.问你先手是否必胜.然后只 ...
- Pod中spec的字段常用字段及含义
一.Pod中spec的字段常用字段及含义 1.pod.spec.containers ² spec.containers.name <string> #pod的名称,必须字段,名称唯一 ...
- nexus私服的搭建和使用
- kindle资源
化繁为简!Kindle 漫画和电子书 资源汇总 & 用法 刚入Kindle那会,在网上翻看了不少文章,有的讲怎么下载电子书,有的讲怎么看漫画,有的讲怎么设置推送邮箱…… 好吧,我不想在用Kin ...
- Docker从入门到实战(三)
Docker从入门到实战(三) 一:安装Docker 1. linux系统脚本安装 Docker基于linux容器技术,面向服务器端,Docker只能安装运行在64位计算机上(社区有对32位的支持), ...
- 成功安装tesserocr
首先按照官网的操作,出现了下面的错误. 错误描述: x86_64-linux-gnu-gcc: error trying to exec 'cc1plus': execvp: 没有那个文件或目录 er ...