由percona-data-recovery-tool恢復ibd資料的工具的一些測試
無意間看到了percona-data-recovery-tool 這個工具,這個工具是用來恢復innodb資料檔案中的資料,貌似都建議row_format必須是REDUNDANT或者COMPACT。而在mysql5.7.8以上預設為Dynamic,但其實在此處我在Dynamic下測試是沒有問題的。
當我們誤刪除某個表資料時,實際上數還存留在資料檔案中,因此可透過特殊手段從資料檔案中抽取相應的資料。
資料被誤刪除後,需要儘快將保護現場,停止資料庫,把 idb 檔案複製出來,防止 ibd 檔案寫入資料被覆蓋。
安裝方法:
yum install glibc-static
yum -y install perl-DBD-MySQL.x86_64
tar -xf percona-data-recovery-tool-for-innodb-0.5.tar.gz
cd percona-data-recovery-tool-for-innodb-0.5
cd mysql-source/
./configure
cd ..
make
解析 ibd 檔案:此處會將ibd檔案以16k為單位分割成n個檔案
./page_parser -5 -f /home/mysql/datal/cwdtest/card.ibd
引數解釋:
-5:代表 row format 為 Compact
-f:代表要解析的檔案,innodb的ibd檔案
[root@xxxx-sql-auditing percona-data-recovery-tool-for-innodb-0.5]# ./page_parser -5 -f /home/mysql/datal/cwdtest/card.ibd Opening file: /home/mysql/datal/cwdtest/card.ibd: 64769 ID of device containing file 189843585 inode number 33184 protection 1 number of hard links 1001 user ID of owner 1001 group ID of owner 0 device ID (if special file) 9437184 total size, in bytes 4096 blocksize for filesystem I/O 18432 number of blocks allocated 1543312312 time of last access 1543394915 time of last modification 1543394915 time of last status change 9437184 Size to process in bytes 104857600 Disk cache size in bytes 83.25% done. 2018-11-28 16:52:19 ETA(in 00:00 hours). Processing speed: 7856357 B/sec
生成表定義
./create_defs.pl -host 127.0.0.1 -port 3306 -user root -password mysql123 -db cwdtest -table card >include/table_defs.h
make
開始恢復 pages 中刪除的資料:
./constraints_parser -5 -D -f ./pages-1543395138/FIL_PAGE_INDEX/0-602/22-00000025.page >/tmp/22-00000025.page.txt
引數:
-5 -f 的引數和 page_parser 相同;
-D:該引數的含義為代表恢復刪除的資料頁;
[root@xxxx-sql-auditing percona-data-recovery-tool-for-innodb-0.5]# ./constraints_parser -5 -D -f ./pages-1543395138/FIL_PAGE_INDEX/0-602/40-00000071.page >/tmp/00000071.sql LOAD DATA INFILE '/usr/local/src/percona-data-recovery-tool-for-innodb-0.5/dumps/default/SYS_TABLES' REPLACE INTO TABLE `SYS_TABLES` FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' LINES STARTING BY 'SYS_TABLES\t' (NAME, ID, N_COLS, TYPE, MIX_ID, MIX_LEN, CLUSTER_NAME, SPACE); [root@xxxx-sql-auditing percona-data-recovery-tool-for-innodb-0.5]# '
然後生成的檔案就用load data 方式插入,其實該方法介紹的文章很多,這裡只給出關鍵步驟。而對於在誤刪資料後是否資料還真的存於ibd中,我這裡做個小小實驗。
表中有三行資料,刪除其中hhhhhhh一行。
mysql> select * from test; +----------+----------+ | col1 | col2 | +----------+----------+ | | aaaaaaaa | | ccccccc | NULL | | hhhhhhhh | xxxxxxxx | +----------+----------+ 3 rows in set (0.00 sec) mysql> delete from test where col1='hhhhhhhh'; Query OK, 1 row affected (0.01 sec)
用hexdump來檢視ibd檔案:
檢視頁結構: python py_innodb_page_info.py -v /data/mysql/cwdtest/test.ibd page offset 00000000, page type <File Space Header> page offset 00000001, page type <Insert Buffer Bitmap> page offset 00000002, page type <File Segment inode> page offset 00000003, page type <B-tree Node>, page level <0000> page offset 00000000, page type <Freshly Allocated Page> page offset 00000000, page type <Freshly Allocated Page> Total number of page: 6: Freshly Allocated Page: 2 Insert Buffer Bitmap: 1 File Space Header: 1 B-tree Node: 1 File Segment inode: 1
對該表資料檔案做個hexdump:
hexdump -C -v /data/mysql/cwdtest/test2.ibd >/tmp/udb.txt
page type <B-tree Node>, page level <0000> 從第四個頁開始,從hexdump中可找到相應的位置0x0000c000開始,16k*3=49152=0x0000c000
0000c000 8c 69 ae 6a 00 00 00 03 ff ff ff ff ff ff ff ff |.i.j............| 0000c010 00 00 00 00 00 29 6a a5 45 bf 00 00 00 00 00 00 |.....)j.E.......| 0000c020 00 00 00 00 00 21 00 02 00 e7 80 05 00 00 00 00 |.....!..........| 0000c030 00 c4 00 02 00 00 00 03 00 00 00 00 00 00 00 00 |................| 0000c040 00 00 00 00 00 00 00 00 00 33 00 00 00 21 00 00 |.........3...!..| 0000c050 00 02 00 f2 00 00 00 21 00 00 00 02 00 32 01 00 |.......!.....2..| 0000c060 02 00 1d 69 6e 66 69 6d 75 6d 00 04 00 0b 00 00 |...infimum......| 0000c070 73 75 70 72 65 6d 75 6d 08 00 00 00 00 10 00 22 |supremum......."| 0000c080 00 00 00 00 02 0d 00 00 00 00 0b 36 ab 00 00 01 |...........6....| 0000c090 22 01 10 61 61 61 61 61 61 61 61 07 01 00 00 18 |"..aaaaaaaa.....| 0000c0a0 00 22 00 00 00 00 02 0e 00 00 00 00 0b 37 ac 00 |."...........7..| 0000c0b0 00 01 23 01 10 63 63 63 63 63 63 63 08 08 00 20 |..#..ccccccc... | 0000c0c0 00 20 ff ac 00 00 00 00 02 0f 00 00 00 00 0b a1 |. ..............| 0000c0d0 76 00 00 01 72 01 10 68 68 68 68 68 68 68 68 78 |v...r..hhhhhhhhx|<<<<<<<<<< 0000c0e0 78 78 78 78 78 78 78 00 00 00 00 00 00 00 00 00 |xxxxxxx.........| 0000c0f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0000c100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0000c110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
發現hhhhhhhh一行是在的,於是做個 analyze,檢視是否會被清除。
mysql> optimize table test; +--------------+----------+----------+-------------------------------------------------------------------+ | Table | Op | Msg_type | Msg_text | +--------------+----------+----------+-------------------------------------------------------------------+ | cwdtest.test | optimize | note | Table does not support optimize, doing recreate + analyze instead | | cwdtest.test | optimize | status | OK | +--------------+----------+----------+-------------------------------------------------------------------+ 2 rows in set (0.03 sec) mysql> analyze table test; +--------------+---------+----------+----------+ | Table | Op | Msg_type | Msg_text | +--------------+---------+----------+----------+ | cwdtest.test | analyze | status | OK | +--------------+---------+----------+----------+
再查hexdump
0000c000 f0 d3 26 ea 00 00 00 03 ff ff ff ff ff ff ff ff |..&.............| 0000c010 00 00 00 00 00 29 7b ce 45 bf 00 00 00 00 00 00 |.....){.E.......| 0000c020 00 00 00 00 00 24 00 02 00 bc 80 04 00 00 00 00 |.....$..........| 0000c030 00 a2 00 02 00 00 00 02 00 00 00 00 00 00 00 00 |................| 0000c040 00 00 00 00 00 00 00 00 00 36 00 00 00 24 00 00 |.........6...$..| 0000c050 00 02 00 f2 00 00 00 24 00 00 00 02 00 32 01 00 |.......$.....2..| 0000c060 02 00 1d 69 6e 66 69 6d 75 6d 00 03 00 0b 00 00 |...infimum......| 0000c070 73 75 70 72 65 6d 75 6d 08 00 00 00 00 10 00 22 |supremum......."| 0000c080 00 00 00 00 02 0d 00 00 00 00 0b 36 ab 00 00 01 |...........6....| 0000c090 22 01 10 61 61 61 61 61 61 61 61 07 01 00 00 18 |"..aaaaaaaa.....| 0000c0a0 ff ce 00 00 00 00 02 0e 00 00 00 00 0b 37 ac 00 |.............7..| 0000c0b0 00 01 23 01 10 63 63 63 63 63 63 63 00 00 00 00 |..#..ccccccc....| 0000c0c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0000c0d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0000c0e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0000c0f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| 0000c100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
此時已被清理掉了。所以,一旦傳送誤刪操作且沒有備份,第一時間應該趕緊把ibd檔案備份。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29863023/viewspace-2222054/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 資料恢復新姿勢——通過ibd和frm檔案恢復資料資料恢復
- Mysql5.7利用frm與ibd恢復資料MySql
- PDM測試資料庫恢復資料庫
- Mysql通過ibd檔案恢復資料的步驟詳解MySql
- rman備份恢復-rman恢復資料檔案測試
- MySQL 5.6.26 通過frm & ibd 恢復資料過程MySql
- MySQL 5.6.26 透過frm & ibd 恢復資料過程MySql
- oracle誤drop/update資料恢復測試Oracle資料恢復
- 測試恢復3==當資料庫處於開啟狀態時的恢復資料庫
- Oracle中truncate table後的資料恢復(Oracle資料恢復工具-ODU)Oracle資料恢復
- 15 款 Windows 的資料恢復工具Windows資料恢復
- 定時做資料庫恢復測試sqlserver資料庫SQLServer
- 硬碟資料恢復工具硬碟資料恢復
- 資料恢復工具PhotoRec資料恢復
- Oracle資料庫的熱備份與完整恢復測試 (2)Oracle資料庫
- Oracle資料庫的熱備份與完整恢復測試 (1)Oracle資料庫
- DB2資料庫的備份測試--開始恢復DB2資料庫
- 使用hellodba的工具恢復truncate表的資料
- Sybase ASE資料庫恢復,Sybase資料恢復,資料誤刪除恢復工具READSYBDEVICE資料庫資料恢復dev
- SQLSERVER恢復測試SQLServer
- Oracle恢復測試Oracle
- 恢復測試:擁有當時的全部歸檔,控制檔案,恢復丟失的資料檔案。
- Disk Drill資料恢復工具資料恢復
- 資料恢復-電腦管家檔案恢復工具資料恢復
- rman 恢復機制與恢復測試
- 【管理篇備份恢復】rman恢復測試(一) 表空間資料檔案
- SQL Server資料庫恢復,SQL Server資料恢復,SQL Server資料誤刪除恢復工具SQLRescueSQLServer資料庫資料恢復
- Oracle資料恢復顧問(DRA)使用測試 (之二)Oracle資料恢復
- Oracle資料恢復顧問(DRA)使用測試 (之一)Oracle資料恢復
- Oracle RMAN恢復測試Oracle
- 【資料庫資料恢復】透過恢復NDF檔案修復資料庫的資料恢復過程資料庫資料恢復
- Sybase SQL Anywhere(ASA)資料庫恢復,ASA資料恢復,資料誤刪除恢復工具ReadASADBSQL資料庫資料恢復
- oradim工具恢復資料庫資料庫
- 使用WT工具恢復MongoDB資料MongoDB
- 恢復資料,資料塊恢復
- 硬碟資料的恢復硬碟
- Oracle常規恢復的實驗測試Oracle
- 11款最棒的Linux資料恢復工具Linux資料恢復