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 ...
随机推荐
- Ansible Jinja2使用
常用方法 ternary 根据结果的真假来决定返回值 - name: Set container backend to "dir" or "lvm" based ...
- Linux系统及lvm知识
一.磁盘分区是怎样表示的 IDE磁盘的设备文件采用/dev/hdx 来命名,分区则采用/dev/hdxy来命名,其中想表示磁盘(a是第一块磁盘,b是第二块磁盘,以此类推),与代表分区的号码(由1开始, ...
- <你的孤独,虽败犹荣> 很喜欢的句子
希望未来的工作中能够经常出差,做一个能看到除了湖南之外的世界的人 即使我们一辈子给人打工,也要打自己愿意打的工 正在经历的孤独,我们称之为迷茫,经过的那些孤独,我们称之为成长 青春,是一个容量极其有限 ...
- Ubuntu常用命令集合
文件操作 查看当前目录: pwd 参考文章:https://blog.csdn.net/qq_33421080/article/details/76551554 应用编辑类 安装: sudo apt- ...
- 如何使用JDBC Request跨数据库查询后引用查询的结果作为下一个JDBC Request的入参
[前言] 今天来给大家介绍下如何使用JDBC Request跨数据库查询后引用查询的结果作为下一个JDBC Request的入参! 因为我现在所测的系统模块中部分表在不同的数据库中,所以在用JDBC ...
- 使用java画一张海报
PS: 没找到合适的海报背景,就随便找了一张,使用技术都是相同的 1. 添加依赖 这俩其实跟本章节的核心技术没有关系,是为了获取QQ昵称和QQ头像而引入的. <!-- jsoup --> ...
- idea中使用Git对项目进行版本控制
- JAVAFX-6 面板总结
说明:转至:https://www.cnblogs.com/lensener/p/7978225.html 便于集中看到这些文章 面板列表: Accordion 手风琴面板:就是一个折叠展开功能,一般 ...
- Vue 2 --v-model、局部组件和全局组件、父子组件传值、平行组件传值
一.表单输入绑定(v-model 指令) 可以用 v-model 指令在表单 <input>.<textarea> 及 <select> 元素上创建双向数据绑定. ...
- Python+Selenium----处理登录图片验证码
1.说明 在做自动化测试的时候,经常会遇到登录,其中比较麻烦的就是验证码的处理,现在比较常用的图形验证码,每次刷新,得到的验证码不一致,所以,一般来说,获取验证码图片有两种方式: (1)拿到验证码的图 ...