0

0

开发误删数据恢复

php中文网

php中文网

发布时间:2016-06-07 16:34:18

|

973人浏览过

|

来源于php中文网

原创

数据平台开发误删数据,但是不知道具体时间点,就给了一个模糊时间,同事使用rollback逆向恢复(解析binlog产生反向sql),我使用备份集恢复apply binlog正向恢复,尽快解决问题 【原正向恢复方式】 选择数据出问题时间之前最近的备份集恢复在一个新实例 (r

数据平台开发误删数据,但是不知道具体时间点,就给了一个模糊时间,同事使用rollback逆向恢复(解析binlog产生反向sql),我使用备份集恢复apply binlog正向恢复,尽快解决问题

【原正向恢复方式】

  • 选择数据出问题时间之前最近的备份集恢复在一个新实例(restorebak.pl恢复工具支持,操作方便)

  • 将备份集pos与数据出问题pos之间的binlog拷贝到新实例上(拷贝binlog操作繁琐)

  • 使用mysqlbinlog –stop-datetime来apply binlog到新实例,以便恢复到数据出问题前的一致性数据快照(mysqlbinlog每次只支持单个binlog apply ,操作繁琐)

其中关于pos点的查找一般都是通过类似mysqlbinlog –no-defaults –stop-datetime=”2012-11-11 11:11:11″ |grep “具体操作” ?-C 3方式来查找的,先通过大体时间段确定一个范围,然后在范围内的精确查找具体的pos

其实mysql有个函数master_pos_wait?可以指定具体pos并返回期间执行事件,于是改进恢复过程,将新实例直接指向原主库拉binlog

【新正向恢复方式】

  • 选择数据出问题时间之前最近的备份集恢复在一个新实例(恢复工具支持,操作方便)
  • start slave;select MASTER_POS_WAIT(‘mysql-bin.000396′,67698920,0);stop slave;?(relay 到指定pos后 触发stop slave操作)
  • show slave status\G;??(保存复制关系)
  • change master to ?master_host=’ ‘, master_user=’slave’,master_password=’slave’;?(取消复制关系,防止误操作开启复制)

【问题】

这种方式在新实例上会多执行几个事件,所以需要将MASTER_POS_WAIT设置的pos提前一些,只适用于基于时间恢复的粗略场景,但是这种场景占绝大多数情况

?MASTER_POS_WAIT(log_name,log_pos[,timeout])

This function is useful for control of master/slave synchronization. It blocks until the slave has read and applied all updates up to the specified position in the master log. The return value is the number of log events the slave had to wait for to advance to the specified position. The function returns?NULL?if the slave SQL thread is not started, the slave’s master information is not initialized, the arguments are incorrect, or an error occurs. It returns?-1?if the timeout has been exceeded. If the slave SQL thread stops while?MASTER_POS_WAIT()?is waiting, the function returns?NULL. If the slave is past the specified position, the function returns immediately.

If a?timeout?value is specified,?MASTER_POS_WAIT()?stops waiting when?timeout?seconds have elapsed.?timeoutmust be greater than 0; a zero or negative?timeout?means no timeout.

This function is unsafe for statement-based replication. Beginning with MySQL 5.5.1, a warning is logged if you use this function when?binlog_format?is set to?STATEMENT. (Bug #47995)

【分享】

后来同事分享其实start slave直接可以指定停止的pos,汗

游戏点卡API接口
游戏点卡API接口

点卡API支付接口支持各大游戏类一卡通接口。优势:1、同行业点卡回收支付业务更全;2、同行业点卡回收处理速度更快;3、同行业点卡回收技术更强,支持多卡同时提交;更新内容:1、增加点卡卡密规则文档,发便开发人员根据卡密位数提交前判断;2、增加点卡api接口密钥申请教程,减少在申请过程担误的时间;3、POST传值加密措施更严谨,同行业内存在多年的不足已修复完善;

下载

START SLAVE [SQL_THREAD] UNTIL MASTER_LOG_FILE = ‘log_name‘, MASTER_LOG_POS =?log_pos

An?UNTIL?clause may be added to specify that the slave should start and run until the SQL thread reaches a given point in the master binary log or in the slave relay log. When the SQL thread reaches that point, it stops. If the?SQL_THREAD?option is specified in the statement, it starts only the SQL thread. Otherwise, it starts both slave threads. If the SQL thread is running, the?UNTIL?clause is ignored and a warning is issued.

For an?UNTIL?clause, you must specify both a log file name and position. Do not mix master and relay log options.

Any?UNTIL?condition is reset by a subsequent?STOP SLAVE?statement, a?START SLAVE?statement that includes noUNTIL?clause, or a server restart.

The?UNTIL?clause can be useful for debugging replication, or to cause replication to proceed until just before the point where you want to avoid having the slave replicate an event. For example, if an unwise?DROP TABLE?statement was executed on the master, you can use?UNTIL?to tell the slave to execute up to that point but no farther. To find what the event is, use?mysqlbinlog?with the master binary log or slave relay log, or by using a?SHOW BINLOG EVENTS?statement.

If you are using?UNTIL?to have the slave process replicated queries in sections, it is recommended that you start the slave with the?–skip-slave-start?option to prevent the SQL thread from running when the slave server starts. It is probably best to use this option in an option file rather than on the command line, so that an unexpected server restart does not cause it to be forgotten.

【最终正向恢复方式】

  • 选择数据出问题时间之前最近的备份集恢复在一个新实例(恢复工具支持,操作方便)
  • start slave until master_log_file=’mysql-bin.000396′,master_log_pos=67698920;
  • show slave status\G;??(保存复制关系)
  • change master to ?master_host=’ ‘, master_user=’slave’,master_password=’slave’;?(取消复制关系,防止误操作开启复制)

【改进】

可以直接把start slave until语句直接做到恢复工具中,很大的收获

感谢印风和智盛的idea,感谢维西的分享

相关文章

数据恢复工具app
数据恢复工具app

手机里的数据丢失了怎么办?聊天记录不小心删掉了怎么办?不用担心,这里为大家提供了数据恢复工具app下载,安全正规,有需要的小伙伴保存下载,就轻松恢复数据啦!

下载

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
go语言 注释编码
go语言 注释编码

本专题整合了go语言注释、注释规范等等内容,阅读专题下面的文章了解更多详细内容。

2

2026.01.31

go语言 math包
go语言 math包

本专题整合了go语言math包相关内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

go语言输入函数
go语言输入函数

本专题整合了go语言输入相关教程内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

golang 循环遍历
golang 循环遍历

本专题整合了golang循环遍历相关教程,阅读专题下面的文章了解更多详细内容。

0

2026.01.31

Golang人工智能合集
Golang人工智能合集

本专题整合了Golang人工智能相关内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

2026赚钱平台入口大全
2026赚钱平台入口大全

2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。

76

2026.01.31

高干文在线阅读网站大全
高干文在线阅读网站大全

汇集热门1v1高干文免费阅读资源,涵盖都市言情、京味大院、军旅高干等经典题材,情节紧凑、人物鲜明。阅读专题下面的文章了解更多详细内容。

73

2026.01.31

无需付费的漫画app大全
无需付费的漫画app大全

想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。

67

2026.01.31

漫画免费在线观看地址大全
漫画免费在线观看地址大全

想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。

19

2026.01.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Node.js 教程
Node.js 教程

共57课时 | 9.9万人学习

Rust 教程
Rust 教程

共28课时 | 5.2万人学习

Vue 教程
Vue 教程

共42课时 | 7.6万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号