利用日誌挖掘 Oracle 不完全恢複 恢複誤刪除的表/資料/視圖等

來源:互聯網
上載者:User

利用日誌挖掘 Oracle 不完全恢複 恢複誤刪除的表/資料/視圖等

  1. /* --------------------------   
  2. 前題:   
  3.   1. DB工作在歸檔模式下;  
  4.   2. 有冷準備份的資料檔案;  
  5. ---------------------------*/  
 
  1. col script for a80  
  2. col SQL_REDO for a80  
  3.   
  4. -- 拼接從哪裡挖的語句   
  5. select 'exec dbms_logmnr.add_logfile('''||member||''')' as script from v$logfile;  
  6.   
  7. -- 從哪裡挖   
  8. exec dbms_logmnr.add_logfile('/oracle/oradata/orcl_new/redo03.log');   
  9. exec dbms_logmnr.add_logfile('/oracle/oradata/orcl_new/redo02.log');  
  10. exec dbms_logmnr.add_logfile('/oracle/oradata/orcl_new/redo01.log');  
  11.   
  12.   
  13. -- 開始挖   
  14. exec dbms_logmnr.start_logmnr;  
  15.   
  16. -- 找結果 --> 要恢複的語句時的時間戳記;   
  17. select scn, sql_redo from v$logmnr_contents where sql_redo like 'drop table emp%';  
  18.    
  19.        SCN SQL_REDO  
  20. ---------- --------------------------------------------------------------------------------   
  21.    1036547 drop table t1 purge;  
  22.    1037333 drop table scott.emp purge;  
  23. --  1037333 -->要恢複的時間戳記   
  24.   
  25. -- 關掉DB    
  26. shutdown abort  
  27.   
  28. -- 拷貝冷備的檔案 -- *.dbf 到資料檔案目錄下,並進行覆蓋;,因為要利用日誌把 sys,user等資料表空間的資料,重做一次;   
  29. [oracle@OracleWeblogic orcl_new_bk]$ cp *.dbf ../orcl_new/  
  30.   
  31. -- 啟動到 mount 下;   
  32. startup mount  
  33.   
  34. -- 恢複到 1037333 drop table scott.emp purge  的時間點;   
  35. -- 要求:trc    
  36. recover database until change 1035742;  
  37.   
  38. -- 啟動DB in resetlogs;   
  39. alter database open resetlogs;  
  40.   
  41.   
  42. 原理  
  43. 1.冷備份的資料檔案 *.dbf比現在要舊,那麼資料檔案的scn肯定就比現在的小;  
  44. 2.使用日誌挖掘方法,在日誌中找出刪表時的scn;  
  45. 3.在資料庫shutdown 的狀態下,用冷備份的資料檔案 *.dbf,覆蓋現在的*.dbf檔案;-- 保證資料檔案完整性   
  46. 4.啟動DB到 mount 下, 恢複到日誌挖掘的時間點(利用日誌對資料檔案重做一次)  
  47. 5.以 resetlog 方式 open --- 以前的日誌就覆蓋了;   
  48.   
  49. PS:資料庫有四種狀態shutdown、nomount、mount、open  
  50. shutdown是指關閉狀態  
  51. nomount是指根參數檔案已經構造出執行個體的狀態  
  52. mount是指為執行個體開啟控制檔案,並讀出控制檔案中相關資訊,但並不驗證  
  53. open是指對相關檔案進行驗證,如沒有問題,就開啟,讓使用者可以訪問  

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.