使用hellodba的工具恢復truncate表的資料
本文根據http://blog.chinaunix.net/uid-23284114-id-3754559.html整理,並測試透過。
實現原理:
引用作者原文如下:
TRUNCATE不會逐個清除使用者資料塊上的資料,而僅僅重置資料字典和後設資料塊上的後設資料(如儲存段頭和擴充套件段圖)。
也就是說,此時,其基本資料並未被破壞,而是被系統回收、等待被重新分配————因此,要恢復被TRUNCATE的資料,需要及時備份其所在的資料檔案。
--參考:移花接木————利用Oracle表掃描機制恢復被Truncate的資料
一、模擬truncate操作:
SQL> conn scott/tiger
SQL> select count(*) from t;
COUNT(*)
----------
13
SQL> truncate table t;
二、恢復truncate表的資料
1.下載hellodba的恢復工具到資料庫伺服器
linux下使用終端,如下:
[oracle@rac1 ~]$ wget
windows下使用IE輸入以下網址:
2.解壓下載下來的FY_Recover_Data.zip
[oracle@rac1 ~]$ unzip FY_Recover_Data.zip
解壓後得到一個檔案FY_Recover_Data.SQL
以下3-7步操作均用sys使用者執行
3.使用sys使用者執行解壓後的指令碼(我這裡解壓後的檔案在/home/oracle/)
SQL> @/home/oracle/FY_Recover_Data.SQL
這個指令碼實際是在sys使用者下建立了一個名為FY_Recover_Data的package
4.使用sys使用者找出存放truncate表的資料檔案路徑,下一步會用到這個檔案路徑
SQL> select file_name from dba_data_files f, dba_tables t where t.owner='SCOTT' and t.table_name='T' and t.tablespace_name = f.tablespace_name;
查得結果是/u01/oracle/oradata/orcl/users01.dbf
5.使用sys使用者執行以下操作開始恢復:
declare
tgtowner varchar2(30);
tgttable varchar2(30);
datapath varchar2(4000);
datadir varchar2(30);
rects varchar2(30);
recfile varchar2(30);
rstts varchar2(30);
rstfile varchar2(30);
blksz number;
rectab varchar2(30);
rsttab varchar2(30);
copyfile varchar2(30);
begin
tgtowner := 'SCOTT'; --table owner
tgttable := 'T'; --table name
datapath := '/u01/oracle/oradata/orcl/'; --必須和被truncate表所在的資料檔案的目錄相同
datadir := 'FY_DATA_DIR'; --oracle中目錄的名字,可以修改
Fy_Recover_data.prepare_files(tgtowner, tgttable, datapath, datadir, rects, recfile, rstts, rstfile, blksz);
Fy_Recover_data.fill_blocks(tgtowner, tgttable, datadir, rects, recfile, rstts, 8, tgtowner, tgtowner, rectab, rsttab, copyfile);
Fy_Recover_data.recover_table(tgtowner, tgttable, tgtowner, rectab, tgtowner, rsttab, datadir, datadir, recfile,datadir, copyfile, blksz);
end;
/
注:執行上的SQL產生2個表空間FY_REC_DATA、FY_RST_DATA,還有1個copy檔案。
6.使用sys使用者把恢復的資料從scott.t$$中插回scott.t表
注:scott.t$$中是scott.t表truncate之前的資料,此時已經把truncate表的資料恢復出來了,放到了scott.t$$中,讓我們去判斷一下恢復的是否正確,正確的話,自己插回原表。
SQL> insert into scott.t select * from scott.t$$;
13 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from t;
COUNT(*)
----------
13
可以看到被truncate的資料已經恢復。
7.使用sys使用者刪除恢復時產生的2個表空間及資料檔案
SQL> drop tablespace fy_rec_data including contents and datafiles;
Tablespace dropped.
SQL> drop tablespace fy_rst_data including contents and datafiles;
Tablespace dropped.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/76103/viewspace-2140176/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用ODU恢復被truncate表的資料
- 使用ODU恢復oracle被truncate的表資料Oracle
- 【資料庫資料恢復】如何恢復Oracle資料庫truncate表的資料資料庫資料恢復Oracle
- Oracle中truncate table後的資料恢復(Oracle資料恢復工具-ODU)Oracle資料恢復
- 恢復被執行truncate table的表資料
- TRUNCATE資料恢復資料恢復
- 【資料庫資料恢復】Oracle資料庫誤truncate table的資料恢復案例資料庫資料恢復Oracle
- 【資料庫資料恢復】誤truncate table的Oracle資料庫資料恢復方案資料庫資料恢復Oracle
- oracle logminer恢復truncate table的資料Oracle
- Oracle Truncate表恢復(ODU)Oracle
- 【北亞資料恢復】誤操作導致雲伺服器表被truncate,表內資料被delete的資料恢復資料恢復伺服器delete
- truncate table 誤刪除資料後的恢復
- 【資料庫資料恢復】oracle資料庫誤truncate table怎麼恢復資料?資料庫資料恢復Oracle
- truncate表後恢復方法總結
- oracle恢復表delete/truncate/drop的方法總結Oracledelete
- 一次truncate table 後的資料恢復[轉帖]資料恢復
- 使用WT工具恢復MongoDB資料MongoDB
- 【北亞資料恢復】oracle資料庫執行truncate table命令怎麼恢復資料?資料恢復Oracle資料庫
- RMAN恢復單個表空間或被DROP/DELETE/TRUNCATE的表delete
- 資料恢復工具Recoverit使用教程:如何修復損壞的影片資料恢復
- 表資料被誤操作的恢復
- 15 款 Windows 的資料恢復工具Windows資料恢復
- 循序漸進oracle第8章:Oracle的閃回特性之恢復truncate刪除表的資料Oracle
- 使用Flashback Transaction方法來恢復資料表資料
- 硬碟資料恢復工具硬碟資料恢復
- 資料恢復工具PhotoRec資料恢復
- 【北亞資料庫資料恢復】使用delete未加where子句刪除全表資料的Mysql資料庫資料恢復資料庫資料恢復deleteMySql
- 【北亞資料恢復】誤刪除oracle表和誤刪除oracle表資料的資料恢復方法資料恢復Oracle
- Sybase ASE資料庫恢復,Sybase資料恢復,資料誤刪除恢復工具READSYBDEVICE資料庫資料恢復dev
- Disk Drill資料恢復工具資料恢復
- rman恢復資料檔案 恢復表空間
- 資料恢復-電腦管家檔案恢復工具資料恢復
- 使用恢復建議恢復資料庫資料庫
- 【備份恢復】不使用rman工具就能恢復被rm刪除的資料檔案案例
- 使用Flashback Database進行資料表級別的定點恢復Database
- 閃回恢復一個表中的資料
- MySQL備份和恢復資料表的方法MySql
- SQL Server資料庫恢復,SQL Server資料恢復,SQL Server資料誤刪除恢復工具SQLRescueSQLServer資料庫資料恢復