误删数据恢复

本文涉及的产品
RDS AI 助手,专业版
RDS MySQL DuckDB 分析主实例,基础系列 4核8GB
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
简介: 数据平台开发误删数据,但是不知道具体时间点,就给了一个模糊时间,同事使用rollback逆向恢复(解析binlog产生反向SQL),我使用备份集恢复apply binlog正向恢复,尽快解决问题 【原正向恢复方式】 选择数据出问题时间之前最近的备份集恢复在一个新实例(restorebak.pl恢复工具支持,操作方便) 将备份集pos与数据出问题pos之间的binlog拷贝

数据平台开发误删数据,但是不知道具体时间点,就给了一个模糊时间,同事使用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,汗
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,感谢维西的分享

【转载地址】
开发误删数据恢复

PS: 偶平时也就这样做了一下.
shell>mysqlbinlog  -d xxx --stop-datetime="xxxx-xx-xx xx:xx:xx" mysqlbin.000004 >> restore.sql
shell>mysql -u root -p --default-character-set=utf-8 < restore.sql
....如果没有建库的SQL,估计就得进库先建,然后 source restore.sql;...

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
23天前
|
人工智能 自然语言处理 Shell
🦞 如何在 OpenClaw (Clawdbot/Moltbot) 配置阿里云百炼 API
本教程指导用户在开源AI助手Clawdbot中集成阿里云百炼API,涵盖安装Clawdbot、获取百炼API Key、配置环境变量与模型参数、验证调用等完整流程,支持Qwen3-max thinking (Qwen3-Max-2026-01-23)/Qwen - Plus等主流模型,助力本地化智能自动化。
33719 134
🦞 如何在 OpenClaw (Clawdbot/Moltbot) 配置阿里云百炼 API
|
6天前
|
人工智能 自然语言处理 监控
OpenClaw skills重构量化交易逻辑:部署+AI全自动炒股指南(2026终极版)
2026年,AI Agent领域最震撼的突破来自OpenClaw(原Clawdbot)——这个能自主规划、执行任务的智能体,用50美元启动资金创造了48小时滚雪球至2980美元的奇迹,收益率高达5860%。其核心逻辑堪称教科书级:每10分钟扫描Polymarket近千个预测市场,借助Claude API深度推理,交叉验证NOAA天气数据、体育伤病报告、加密货币链上情绪等多维度信息,捕捉8%以上的定价偏差,再通过凯利准则将单仓位严格控制在总资金6%以内,实现低风险高频套利。
2821 11
|
19天前
|
人工智能 安全 机器人
OpenClaw(原 Clawdbot)钉钉对接保姆级教程 手把手教你打造自己的 AI 助手
OpenClaw(原Clawdbot)是一款开源本地AI助手,支持钉钉、飞书等多平台接入。本教程手把手指导Linux下部署与钉钉机器人对接,涵盖环境配置、模型选择(如Qwen)、权限设置及调试,助你快速打造私有、安全、高权限的专属AI助理。(239字)
7274 21
OpenClaw(原 Clawdbot)钉钉对接保姆级教程 手把手教你打造自己的 AI 助手
|
18天前
|
人工智能 机器人 Linux
OpenClaw(Clawdbot、Moltbot)汉化版部署教程指南(零门槛)
OpenClaw作为2026年GitHub上增长最快的开源项目之一,一周内Stars从7800飙升至12万+,其核心优势在于打破传统聊天机器人的局限,能真正执行读写文件、运行脚本、浏览器自动化等实操任务。但原版全英文界面对中文用户存在上手门槛,汉化版通过覆盖命令行(CLI)与网页控制台(Dashboard)核心模块,解决了语言障碍,同时保持与官方版本的实时同步,确保新功能最快1小时内可用。本文将详细拆解汉化版OpenClaw的搭建流程,涵盖本地安装、Docker部署、服务器远程访问等场景,同时提供环境适配、问题排查与国内应用集成方案,助力中文用户高效搭建专属AI助手。
5130 12
|
20天前
|
人工智能 机器人 Linux
保姆级 OpenClaw (原 Clawdbot)飞书对接教程 手把手教你搭建 AI 助手
OpenClaw(原Clawdbot)是一款开源本地AI智能体,支持飞书等多平台对接。本教程手把手教你Linux下部署,实现数据私有、系统控制、网页浏览与代码编写,全程保姆级操作,240字内搞定专属AI助手搭建!
5901 23
保姆级 OpenClaw (原 Clawdbot)飞书对接教程 手把手教你搭建 AI 助手

热门文章

最新文章