溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Oracle手工不完全恢復(fù)(一):使用當(dāng)前控制文件

發(fā)布時(shí)間:2020-08-07 09:27:07 來源:ITPUB博客 閱讀:162 作者:迷倪小魏 欄目:關(guān)系型數(shù)據(jù)庫

實(shí)驗(yàn)環(huán)境

操作系統(tǒng):CentOS 7.1

數(shù)據(jù)庫:Oracle 11.2.0.4


目錄

示例一:基于SCN或時(shí)間點(diǎn)的恢復(fù)----恢復(fù)過去某個(gè)時(shí)間誤刪除的表

示例二:當(dāng)前日志組損壞,造成數(shù)據(jù)庫崩潰

示例三:歸檔日志丟失或損壞



示例一:基于SCN或時(shí)間點(diǎn)的恢復(fù)----恢復(fù)過去某個(gè)時(shí)間誤刪除的表


環(huán)境:

1)提前對(duì)數(shù)據(jù)庫做一次全庫冷備份;

2)在seiang用戶下有一張test1表隸屬于seiang表空間;


定位錯(cuò)誤操作發(fā)生的時(shí)間或SCNlogminer

恢復(fù)原理: 

1.冷備份的數(shù)據(jù)文件*.dbf比現(xiàn)在要舊,那么數(shù)據(jù)文件的scn肯定就比現(xiàn)在的??;  

2.使用日志挖掘方法,在日志中找出刪表時(shí)的scn或時(shí)間戳;  

3.在數(shù)據(jù)庫shutdown的狀態(tài)下,用冷備份的數(shù)據(jù)文件*.dbf,覆蓋現(xiàn)在的*.dbf文件;保證數(shù)據(jù)文件完整性;

4.啟動(dòng)數(shù)據(jù)庫到mount,恢復(fù)到日志挖掘的SCN或時(shí)間點(diǎn)(利用日志對(duì)數(shù)據(jù)文件重做一次)  

5.以resetlogs方式打開數(shù)據(jù)庫,以前的日志就被覆蓋了;


示例二:當(dāng)前日志組損壞,造成數(shù)據(jù)庫崩潰


環(huán)境:

1)提前對(duì)數(shù)據(jù)庫做一次全庫冷備份;

2)在seiang用戶下有一張test1表隸屬于seiang表空間;


示例三:歸檔日志丟失或損壞


環(huán)境:

1)提前有一套完成的數(shù)據(jù)文件的冷備份;

2)在seiang用戶下有一張test1表隸屬于seiang表空間;

  1. SYS@seiang11g>select owner,table_name,tablespace_name from dba_tables where owner='SEIANG';

  2. OWNER TABLE_NAME TABLESPACE_NAME
  3. ------------------------------ ------------------------------ ------------------------------
  4. SEIANG TEST1 SEIANG
  5. SEIANG TEST2 WJQ
  6. SEIANG TEST3 WJQBEST

  7. SYS@seiang11g>select * from seiang.test1;

  8.         ID NAME AGE
  9. ---------- ------------------------------ ----------
  10.          1 wjq 23
  11.          2 seiang 24
  12.          3 wjqdood 25
  13.          4 wjqbest 30

  14. --查看當(dāng)前日志序號(hào)為2
  15. SYS@seiang11g>select group#,sequence#,status from v$log;

  16.     GROUP# SEQUENCE# STATUS
  17. ---------- ---------- ----------------
  18.          1 1 INACTIVE
  19.          2 2 CURRENT
  20.          3 0 UNUSED


  21. --修改數(shù)據(jù)并提交(sequence號(hào)2)
  22. SYS@seiang11g>update seiang.test1 set age=100 where id=1;
  23. 1 row updated.

  24. SYS@seiang11g>commit;
  25. Commit complete.

  26. SYS@seiang11g>alter system switch logfile;
  27. System altered.

  28. --修改數(shù)據(jù)并提交(sequence號(hào)3)
  29. SYS@seiang11g>update seiang.test1 set age=200 where id=1;
  30. 1 row updated.

  31. SYS@seiang11g>commit;
  32. Commit complete.

  33. SYS@seiang11g>alter system switch logfile;
  34. System altered.

  35. --修改數(shù)據(jù)并提交(sequence號(hào)4)
  36. SYS@seiang11g>update seiang.test1 set age=300 where id=1;
  37. 1 row updated.

  38. SYS@seiang11g>commit;
  39. Commit complete.

  40. SYS@seiang11g>alter system switch logfile;
  41. System altered.

  42. --修改數(shù)據(jù)并提交(sequence號(hào)5)
  43. SYS@seiang11g>update seiang.test1 set age=400 where id=1;
  44. 1 row updated.

  45. SYS@seiang11g>commit;
  46. Commit complete.

  47. SYS@seiang11g>alter system switch logfile;
  48. System altered.

  49. --修改數(shù)據(jù)并提交(sequence號(hào)6)
  50. SYS@seiang11g>update seiang.test1 set age=500 where id=1;
  51. 1 row updated.

  52. SYS@seiang11g>commit;
  53. Commit complete.

  54. SYS@seiang11g>alter system switch logfile;
  55. System altered.

  56. --修改數(shù)據(jù)并提交(sequence號(hào)7)
  57. SYS@seiang11g>update seiang.test1 set age=600 where id=1;
  58. 1 row updated.

  59. SYS@seiang11g>commit;
  60. Commit complete.

  61. SYS@seiang11g>alter system switch logfile;
  62. System altered.

  63. --當(dāng)前聯(lián)機(jī)日志序號(hào)為8
  64. SYS@seiang11g>select group#,sequence#,status from v$log;

  65.     GROUP# SEQUENCE# STATUS
  66. ---------- ---------- ----------------
  67.          1 7 ACTIVE
  68.          2 8 CURRENT
  69.          3 6 ACTIVE

  70. --查看相應(yīng)的歸檔日志
  71. SYS@seiang11g>select name from v$archived_log;

  72. NAME
  73. ------------------------------------------------------
  74. /u01/app/oracle/arch/arch_1_950962051_1.log
  75. /u01/app/oracle/arch/arch_1_950962051_2.log
  76. /u01/app/oracle/arch/arch_1_950971495_1.log
  77. /u01/app/oracle/arch/arch_1_950971495_2.log
  78. /u01/app/oracle/arch/arch_1_950972396_1.log
  79. /u01/app/oracle/arch/arch_1_950972396_2.log
  80. /u01/app/oracle/arch/arch_1_950972396_3.log
  81. /u01/app/oracle/arch/arch_1_950972396_4.log
  82. /u01/app/oracle/arch/arch_1_950972396_5.log
  83. /u01/app/oracle/arch/arch_1_950972396_6.log
  84. /u01/app/oracle/arch/arch_1_950972396_7.log

  85. --關(guān)閉數(shù)據(jù)庫
  86. SYS@seiang11g >shutdown immediate
  87. Database closed.
  88. Database dismounted.
  89. ORACLE instance shut down.

  90. --模擬數(shù)據(jù)文件seiang損壞
  91. SYS@seiang11g>host rm /u01/app/oracle/oradata/OraDB11g/seiang01.dbf


  92. --重新打開數(shù)據(jù)庫 ,由于數(shù)據(jù)文件的丟死,數(shù)據(jù)庫無法open
  93. SYS@seiang11g>startup
  94. ORACLE instance started.

  95. Total System Global Area 1252663296 bytes
  96. Fixed Size 2252824 bytes
  97. Variable Size 788533224 bytes
  98. Database Buffers 452984832 bytes
  99. Redo Buffers 8892416 bytes
  100. Database mounted.
  101. ORA-01157: cannot identify/lock data file 7 - see DBWR trace file
  102. ORA-01110: data file 7: '/u01/app/oracle/oradata/OraDB11g/seiang01.dbf'


  103. SYS@seiang11g>select * from v$recover_file;

  104.      FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
  105. ---------- ------- ------- ----------------------------------------------------------------- ---------- ---------
  106.          7 ONLINE ONLINE FILE NOT FOUND 0

  107. --還原備份的數(shù)據(jù)文件
  108. SYS@seiang11g>host cp /u01/app/oracle/UMAN_Backup/seiang01.dbf /u01/app/oracle/oradata/OraDB11g/
  109.     
  110. SYS@seiang11g>select * from v$recover_file;

  111.      FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
  112. ---------- ------- ------- ----------------------------------------------------------------- ---------- ---------
  113.          7 ONLINE ONLINE UNKNOWN ERROR 1913765 02-AUG-17


  114. --查看一下歸檔日志的詳細(xì)信息
  115. SYS@seiang11g>select sequence#, name, first_change#, next_change# from v$archived_log;

  116.  SEQUENCE# NAME FIRST_CHANGE# NEXT_CHANGE#
  117. ---------- -------------------------------------------------- ------------- ------------
  118.         1 /u01/app/oracle/arch/arch_1_950962051_1.log 1914744 1921854
  119.          2 /u01/app/oracle/arch/arch_1_950962051_2.log 1921854 1921883
  120.          1 /u01/app/oracle/arch/arch_1_950971495_1.log 1913766 1914386
  121.          2 /u01/app/oracle/arch/arch_1_950971495_2.log 1914386 1914401
  122.          1 /u01/app/oracle/arch/arch_1_950972396_1.log 1914402 1936446
  123.          2 /u01/app/oracle/arch/arch_1_950972396_2.log 1936446 1937042
  124.          3 /u01/app/oracle/arch/arch_1_950972396_3.log 1937042 1937100
  125.          4 /u01/app/oracle/arch/arch_1_950972396_4.log 1937100 1937110
  126.          5 /u01/app/oracle/arch/arch_1_950972396_5.log 1937110 1937123
  127.          6 /u01/app/oracle/arch/arch_1_950972396_6.log 1937123 1937139
  128.          7 /u01/app/oracle/arch/arch_1_950972396_7.log 1937139 1937148


  129. --模擬歸檔日志5丟失或者損壞
  130. SYS@seiang11g>host rm /u01/app/oracle/arch/arch_1_950972396_5.log

  131. [oracle@seiang11g OraDB11g]$ ll /u01/app/oracle/arch/arch_1_950972396_5.log
  132. ls: cannot access /u01/app/oracle/arch/arch_1_950972396_5.log: No such file or directory


  133. --執(zhí)行恢復(fù)操作,當(dāng)在需要?dú)w檔日志5的時(shí)候出現(xiàn)錯(cuò)誤
  134. SYS@seiang11g>recover datafile 7;
  135. ORA-00279: change 1913766 generated at 08/02/2017 11:12:22 needed for thread 1
  136. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950971495_1.log
  137. ORA-00280: change 1913766 for thread 1 is in sequence #1

  138. Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
  139. auto
  140. ORA-00279: change 1914386 generated at 08/02/2017 14:48:59 needed for thread 1
  141. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950971495_2.log
  142. ORA-00280: change 1914386 for thread 1 is in sequence #2

  143. ORA-00279: change 1914402 generated at 08/02/2017 14:59:56 needed for thread 1
  144. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_1.log
  145. ORA-00280: change 1914402 for thread 1 is in sequence #1

  146. ORA-00279: change 1936446 generated at 08/02/2017 15:39:52 needed for thread 1
  147. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_2.log
  148. ORA-00280: change 1936446 for thread 1 is in sequence #2

  149. ORA-00279: change 1937042 generated at 08/02/2017 15:49:42 needed for thread 1
  150. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_3.log
  151. ORA-00280: change 1937042 for thread 1 is in sequence #3

  152. ORA-00279: change 1937100 generated at 08/02/2017 15:51:34 needed for thread 1
  153. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_4.log
  154. ORA-00280: change 1937100 for thread 1 is in sequence #4

  155. ORA-00279: change 1937110 generated at 08/02/2017 15:51:54 needed for thread 1
  156. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_5.log
  157. ORA-00280: change 1937110 for thread 1 is in sequence #5

  158. ORA-00308: cannot open archived log '/u01/app/oracle/arch/arch_1_950972396_5.log'
  159. ORA-27037: unable to obtain file status
  160. Linux-x86_64 Error: 2: No such file or directory
  161. Additional information: 3
  162.     
  163. --查看數(shù)據(jù)文件頭,發(fā)現(xiàn)檢查點(diǎn)不一致
  164. SYS@seiang11g>select file#,name,checkpoint_change# from v$datafile_header;

  165.      FILE# NAME CHECKPOINT_CHANGE#
  166. ---------- -------------------------------------------------- ------------------
  167.          1 /u01/app/oracle/oradata/OraDB11g/system01.dbf 1937617
  168.          2 /u01/app/oracle/oradata/OraDB11g/sysaux01.dbf 1937617
  169.          3 /u01/app/oracle/oradata/OraDB11g/undotbs01.dbf 1937617
  170.          4 /u01/app/oracle/oradata/OraDB11g/users01.dbf 1937617
  171.          5 /u01/app/oracle/oradata/OraDB11g/example01.dbf 1937617
  172.          6 /u01/app/oracle/oradata/OraDB11g/rman01.dbf 1937617
  173.          7 /u01/app/oracle/oradata/OraDB11g/seiang01.dbf 1937110
  174.          8 /u01/app/oracle/oradata/OraDB11g/wjq01.dbf 1937617
  175.          9 /u01/app/oracle/oradata/OraDB11g/wjqbest01.dbf 1937617
  1. --關(guān)閉數(shù)據(jù)庫 ,還原所有冷備份的數(shù)據(jù)文件

    SYS@seiang11g>shutdown abort

    ORACLE instance shut down.


    SYS@seiang11g>host cp /u01/app/oracle/UMAN_Backup/*.dbf /u01/app/oracle/oradata/OraDB11g/

  2. SYS@seiang11g>host ls -l /u01/app/oracle/oradata/OraDB11g/
  3. total 2279068
  4. -rw-r----- 1 oracle oinstall 7680 Aug 2 16:08 arch_1_950972396_5.log
  5. -rw-r----- 1 oracle oinstall 9781248 Aug 2 16:16 control01.ctl
  6. -rw-r----- 1 oracle oinstall 363077632 Aug 2 16:17 example01.dbf
  7. -rw-r----- 1 oracle oinstall 52429312 Aug 2 15:52 redo01.log
  8. -rw-r----- 1 oracle oinstall 52429312 Aug 2 15:58 redo02.log
  9. -rw-r----- 1 oracle oinstall 52429312 Aug 2 15:52 redo03.log
  10. -rw-r----- 1 oracle oinstall 31465472 Aug 2 16:17 rman01.dbf
  11. -rw-r----- 1 oracle oinstall 73408512 Aug 2 16:17 seiang01.dbf
  12. -rw-r----- 1 oracle oinstall 734011392 Aug 2 16:18 sysaux01.dbf
  13. -rw-r----- 1 oracle oinstall 796925952 Aug 2 16:18 system01.dbf
  14. -rw-r----- 1 oracle oinstall 30416896 Aug 2 16:18 temp01.dbf
  15. -rw-r----- 1 oracle oinstall 110108672 Aug 2 16:18 undotbs01.dbf
  16. -rw-r----- 1 oracle oinstall 5251072 Aug 2 16:18 users01.dbf
  17. -rw-r----- 1 oracle oinstall 20979712 Aug 2 16:18 wjq01.dbf
  18. -rw-r----- 1 oracle oinstall 20979712 Aug 2 16:18 wjqbest01.dbf

  19. --重新打開數(shù)據(jù)庫
  20. SYS@seiang11g>startup
  21. ORACLE instance started.

  22. Total System Global Area 1252663296 bytes
  23. Fixed Size 2252824 bytes
  24. Variable Size 788533224 bytes
  25. Database Buffers 452984832 bytes
  26. Redo Buffers 8892416 bytes
  27. Database mounted.
  28. ORA-01190: control file or data file 1 is from before the last RESETLOGS
  29. ORA-01110: data file 1: '/u01/app/oracle/oradata/OraDB11g/system01.dbf'


  30. SYS@seiang11g>select file#,name,checkpoint_change# from v$datafile_header;

  31.      FILE# NAME CHECKPOINT_CHANGE#
  32. ---------- -------------------------------------------------- ------------------
  33.          1 /u01/app/oracle/oradata/OraDB11g/system01.dbf 1913765
  34.          2 /u01/app/oracle/oradata/OraDB11g/sysaux01.dbf 1913765
  35.          3 /u01/app/oracle/oradata/OraDB11g/undotbs01.dbf 1913765
  36.          4 /u01/app/oracle/oradata/OraDB11g/users01.dbf 1913765
  37.          5 /u01/app/oracle/oradata/OraDB11g/example01.dbf 1913765
  38.          6 /u01/app/oracle/oradata/OraDB11g/rman01.dbf 1913765
  39.          7 /u01/app/oracle/oradata/OraDB11g/seiang01.dbf 1913765
  40.          8 /u01/app/oracle/oradata/OraDB11g/wjq01.dbf 1913765
  41.          9 /u01/app/oracle/oradata/OraDB11g/wjqbest01.dbf 1913765

  42. 9 rows selected.

  43. --恢復(fù)數(shù)據(jù)庫 ,首先嘗試完全恢復(fù),同樣在需要?dú)w檔日志5的時(shí)候出現(xiàn)錯(cuò)誤
  44. SYS@seiang11g>recover database;
  45. ORA-00279: change 1913766 generated at 08/02/2017 11:12:22 needed for thread 1
  46. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950971495_1.log
  47. ORA-00280: change 1913766 for thread 1 is in sequence #1

  48. Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
  49. auto
  50. ORA-00279: change 1914386 generated at 08/02/2017 14:48:59 needed for thread 1
  51. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950971495_2.log
  52. ORA-00280: change 1914386 for thread 1 is in sequence #2

  53. ORA-00279: change 1914402 generated at 08/02/2017 14:59:56 needed for thread 1
  54. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_1.log
  55. ORA-00280: change 1914402 for thread 1 is in sequence #1

  56. ORA-00279: change 1936446 generated at 08/02/2017 15:39:52 needed for thread 1
  57. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_2.log
  58. ORA-00280: change 1936446 for thread 1 is in sequence #2

  59. ORA-00279: change 1937042 generated at 08/02/2017 15:49:42 needed for thread 1
  60. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_3.log
  61. ORA-00280: change 1937042 for thread 1 is in sequence #3

  62. ORA-00279: change 1937100 generated at 08/02/2017 15:51:34 needed for thread 1
  63. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_4.log
  64. ORA-00280: change 1937100 for thread 1 is in sequence #4

  65. ORA-00279: change 1937110 generated at 08/02/2017 15:51:54 needed for thread 1
  66. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_5.log
  67. ORA-00280: change 1937110 for thread 1 is in sequence #5

  68. ORA-00308: cannot open archived log '/u01/app/oracle/arch/arch_1_950972396_5.log'
  69. ORA-27037: unable to obtain file status
  70. Linux-x86_64 Error: 2: No such file or directory
  71. Additional information: 3


  72. --執(zhí)行不完全恢復(fù) ,成功
  73. SYS@seiang11g>recover database until cancel;
  74. ORA-00279: change 1937110 generated at 08/02/2017 15:51:54 needed for thread 1
  75. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_5.log
  76. ORA-00280: change 1937110 for thread 1 is in sequence #5


  77. Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
  78. cancel
  79. Media recovery cancelled.

  80. --再次查看數(shù)據(jù)文件頭的相關(guān)信息
  81. SYS@seiang11g>select file#,name,checkpoint_change# from v$datafile_header;

  82.      FILE# NAME CHECKPOINT_CHANGE#
  83. ---------- -------------------------------------------------- ------------------
  84.          1 /u01/app/oracle/oradata/OraDB11g/system01.dbf 1937110
  85.          2 /u01/app/oracle/oradata/OraDB11g/sysaux01.dbf 1937110
  86.          3 /u01/app/oracle/oradata/OraDB11g/undotbs01.dbf 1937110
  87.          4 /u01/app/oracle/oradata/OraDB11g/users01.dbf 1937110
  88.          5 /u01/app/oracle/oradata/OraDB11g/example01.dbf 1937110
  89.          6 /u01/app/oracle/oradata/OraDB11g/rman01.dbf 1937110
  90.          7 /u01/app/oracle/oradata/OraDB11g/seiang01.dbf 1937110
  91.          8 /u01/app/oracle/oradata/OraDB11g/wjq01.dbf 1937110
  92.          9 /u01/app/oracle/oradata/OraDB11g/wjqbest01.dbf 1937110

  93. --查看日志組信息,發(fā)現(xiàn)與5號(hào)脫節(jié)
  94. SYS@seiang11g>select group#,sequence#,status from v$log;

  95.     GROUP# SEQUENCE# STATUS
  96. ---------- ---------- ----------------
  97.          1 7 INACTIVE
  98.          3 6 INACTIVE
  99.          2 8 CURRENT

  100. --使用resetlogs打開數(shù)據(jù)庫
  101. SYS@seiang11g>alter database open resetlogs;
  102. Database altered.

  103. --日志序號(hào)從1開始記錄
  104. SYS@seiang11g>select group#,sequence#,status from v$log;

  105.     GROUP# SEQUENCE# STATUS
  106. ---------- ---------- ----------------
  107.          1 1 CURRENT
  108.          2 0 UNUSED
  109.          3 0 UNUSED

  110. --確認(rèn)表中的數(shù)據(jù)信息,發(fā)現(xiàn)在5號(hào)歸檔日志丟失后的修改都沒有生效
  111. SYS@seiang11g>select * from seiang.test1;

  112.         ID NAME AGE
  113. ---------- -------------------------------------------------- ----------
  114.          1 wjq 300
  115.          2 seiang 24
  116.          3 wjqdood 25
  117.          4 wjqbest 30


相關(guān)連接:

 Oracle手工完全恢復(fù)案例:http://blog.itpub.net/31015730/viewspace-2142669/


作者:SEian.G(苦練七十二變,笑對(duì)八十一難)

ITPUBhttp://blog.itpub.net/31015730/

51CTOhttp://seiang.blog.51cto.com/



向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI