Home Database Mysql Tutorial 无全量备份、未开启binlog日志,利用percona工具恢复delete的数据

无全量备份、未开启binlog日志,利用percona工具恢复delete的数据

Jun 07, 2016 pm 04:48 PM
delete recover

当我们忘记做全量备份时,并且没有开启binlog,并执行了deletefromsbtest;数据全部丢失,要想恢复是很有难度的。今天,利用PerconaDataRecoveryToolforInnoDB工

当我们忘记做全量备份时,并且没有开启binlog,并执行了

delete from sbtest;

数据全部丢失,要想恢复是很有难度的。


今天,利用Percona Data Recovery Tool for InnoDB工具(仅支持InnoDB,MyISAM不支持),可以找回被删除的数据。


原理:在InnoDB引擎,delete删除操作,,不是真正的删除物理文件上的行,而是增加一个删除的标记,我们都用过WORD吧?在修改字体的时候,有一个删除线的标记,如《MySQL 管理之道》,该工具利用这个特性,找回那些标注了删除线的数据,并存入到一个文本里,然后通过load data命令,批量插入到表里。


注:truncate不能恢复(truncate是直接清空数据行,并不是添加删除标记,你可以通过查看物理文件,执行了truncate操作,ibd文件变小,而执行了delete操作,ibd文件还跟之前的一样大),drop不能恢复(数据文件都没了,还怎么恢复?)。


一、安装Percona Data Recovery Tool for InnoDB工具

# wget https://launchpad.net/percona-data-recovery-tool-for-innodb/trunk/release-0.5/+download/percona-data-recovery-tool-for-innodb-0.5.tar.gz

# cd percona-data-recovery-tool-for-innodb-0.5/mysql-source # ./configure # cd .. # make

二、全表删除sbtest表

delete from sbtest;

三、恢复

1、提取ibd物理文件,按照每页16K,单独存放。

# cd percona-data-recovery-tool-for-innodb-0.5/ # ./page_parser -5 -f /usr/local/mysql-5.5.37/data/test/sbtest.ibd

在这里,0-28是sbtest表的主键(id),0-29是sbtest表的索引(k)。记住这个目录数字,后面我们需要通过这个目录恢复数据。


2、生成表结构

# cd percona-data-recovery-tool-for-innodb-0.5/ # ./create_defs.pl --host localhost --port 3306 --user root --password 123456 --db test --table sbtest > include/table_defs.h

-- host 主机地址

-- port 端口

-- user 用户名

-- password 密码

-- db 数据库名

-- table 表名


3、再次执行make编译命令

# cd percona-data-recovery-tool-for-innodb-0.5/ # make

wKiom1QWj3nzmDC0AAUbkA6b0jc746.jpg


4、恢复删除的数据

# cd percona-data-recovery-tool-for-innodb-0.5/ # ./constraints_parser -D -5 -f pages-1410414511/FIL_PAGE_INDEX/0-28/ > /tmp/sbtest.txt

-D 恢复删除的行

-5 表的文件格式,默认是Compact

(不清楚的朋友,可以用show table status命令查看)


总结:

通过上述方法,顺利的完成了delete数据恢复。在数据被删除后,切记要备份ibd数据文件,一定不要覆盖,否则都是不能完成修复的。目前该工具不支持字符串set类型。



本文出自 “贺春旸的技术专栏” 博客,请务必保留此出处

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the delete key on the keyboard? What is the delete key on the keyboard? Mar 16, 2023 pm 04:48 PM

There are two keyboard delete keys: del (delete) key and backspace key. Backspace is also called the backspace key. This key can delete the text content in front of the cursor; and the delete key can delete characters, files and selected objects. Each time you press the del key, a character to the right of the cursor will be deleted, and the character to the right of the cursor will move one frame to the left; when one or more files/folders are selected, press the Del key to quickly delete; in some applications Select an object in the program and press the Del key to quickly delete the selected object.

What is the function of delete key What is the function of delete key Mar 10, 2023 pm 06:07 PM

The functions of the delete key are: 1. Delete characters; each time the delete key is pressed, a character to the right of the cursor will be deleted, and the character to the right of the cursor will move one frame to the left. 2. Delete files; when one or more files/folders are selected, press the Delete key to quickly delete them (move to the Recycle Bin for recovery). 3. Delete the selected object; select an object in some applications and press the Delete key to quickly delete the selected object.

How to Control + Alt + Delete: Mac Tutorial How to Control + Alt + Delete: Mac Tutorial Apr 16, 2023 pm 12:37 PM

Control+Alt+Delete: "Mac" mode Ctrlaltdel is a common key combination used by Windows users to open Task Manager. They usually exit unwanted applications from the manager menu to free up some space on their computer. The Control+Alt+Delete Mac variant lets you open the Force Quit menu. If Mac users want to quit the program causing the problem or view open programs, they can interact with the menu to investigate further. How to perform ControlAltDelete on Mac? If you have any malfunctioning applications, you must use this key combination to

How to use PUT and Delete requests in SpringBoot How to use PUT and Delete requests in SpringBoot May 13, 2023 pm 12:16 PM

PUT and Delete requests are used in the Form form and only support get and post methods. In order to implement the put method, we can implement it through the following three steps: 1) Configure HiddenHttpMethodFilter in SpringMVC 2) Create a post form on the page 3) Create an input item, name ="_method", the value is the specified request method. Get the value of "_method" in the HiddenHttpMethodFilter class to get the new request method. The th tag is the thymeleaf template, which means that only when employee

panic and recovery in Golang exception handling panic and recovery in Golang exception handling Apr 15, 2024 pm 06:15 PM

In Go, Panic and Recover are used for exception handling. Panic is used to report exceptions, and Recover is used to recover from exceptions. Panic will stop program execution and throw an exception value of type interface{}. Recover can catch exceptions from deferred functions or goroutines and return the exception value of type interface{} it throws.

Can deleted files be recovered? Can deleted files be recovered? Feb 24, 2023 pm 03:49 PM

Files deleted by delete can be recovered; because when users use delete to delete files, these files will be moved to the recycle bin and are not completely deleted. Recovery method: 1. Open the "Recycle Bin", select the file you want to restore, and click "Restore this item"; 2. Open the "Recycle Bin", select the file you want to restore, and use the undo shortcut "ctrl+z". Can.

How to add, edit and delete table rows in jQuery? How to add, edit and delete table rows in jQuery? Sep 05, 2023 pm 09:49 PM

In today's era of web development, effective and efficient table management has become very important, especially when dealing with data-heavy web applications. The ability to dynamically add, edit, and delete rows from a table can significantly enhance the user experience and make applications more interactive. An effective way to achieve this is to leverage the power of jQuery. jQuery provides many features to help developers perform operations. Table rows A table row is a collection of interrelated data, represented by elements in HTML. It is used to group together cells (represented by elements) in a table. Each element is used to define a row in the table, and for multi-attribute tables, it usually contains one or more elements. Syntax$(selector).append(co

The application of golang framework panic and recovery in debugging The application of golang framework panic and recovery in debugging Jun 04, 2024 pm 01:01 PM

Panic in the Go framework is used to raise unrecoverable exceptions, and Recover is used to recover from Panic and perform cleanup operations. They can handle exceptions such as database connection failures, ensuring application stability and user experience.

See all articles