Oracle備份/恢復案例05——LogFile恢復
一、損壞非當前聯機日志
?
大家都清楚,聯機日志分為當前聯機日志和非當前聯機日志,非當前聯機日志的損壞是比較簡單的,一般通過clear命令就可以解決問題。
?
1、關閉數據庫,刪除重做日志文件
?
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
Database dismounted.
ORACLE instance shut down.
?
C:>del D:\oracle\oradata\dodo\REDO03.LOG
?
2、啟動數據庫,遇到ORA-00312 or ORA-00313錯誤,如
?
SQL> startup;
ORACLE instance started.
ORACLE instance started.
Total System Global Area? 135338868 bytes
Fixed Size?????????????????? 453492 bytes
Variable Size???????????? 109051904 bytes
Database Buffers?????????? 25165824 bytes
Redo Buffers???????????????? 667648 bytes
Database mounted.
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO03.LOG'
Fixed Size?????????????????? 453492 bytes
Variable Size???????????? 109051904 bytes
Database Buffers?????????? 25165824 bytes
Redo Buffers???????????????? 667648 bytes
Database mounted.
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO03.LOG'
從這里我們知道日志組3的數據文件損壞了
從報警文件可以看到更詳細的信息
從報警文件可以看到更詳細的信息
?
3、查看V$log視圖
?
SQL> select group#,sequence#,archived,status from v$log;
??? GROUP#? SEQUENCE# ARCHIVED?? STATUS
---------- ---------- ---------- -----------
???????? 1????????? 1 NO???????? CURRENT
???????? 2????????? 0 YES??????? UNUSED
???????? 3????????? 0 YES??????? UNUSED
??? GROUP#? SEQUENCE# ARCHIVED?? STATUS
---------- ---------- ---------- -----------
???????? 1????????? 1 NO???????? CURRENT
???????? 2????????? 0 YES??????? UNUSED
???????? 3????????? 0 YES??????? UNUSED
可以知道,該組是非當前狀態,而且已經歸檔。
4、用CLEAR命令重建該日志文件
SQL>alter database clear logfile group 3;
如果是該日志組還沒有歸檔,則需要用:
SQL>alter database clear unarchived logfile group 3;
5、打開數據庫,重新備份數據庫
SQL>alter database open;
?
?
說明:
1、如果損壞的是非當前的聯機日志文件,一般只需要clear就可以重建該日志文件,但是如果該數據庫處于歸檔狀態但該日志還沒有歸檔,就需要強行clear。
2、建議clear,特別是強行clear后作一次數據庫的全備份。
3、此方法適用于歸檔與非歸檔數據庫
?
?
二、 損壞當前聯機日志
歸檔模式下當前日志的損壞有兩種情況:
?
一、是數據庫是正常關閉,日志文件中沒有未決的事務需要實例恢復,當前日志組的損壞就可以直接用alter database clear unarchived logfile group n來重建。
二、是日志組中有活動的事務,數據庫需要介質恢復,日志組需要用來同步,有兩種補救辦法:
??? A. 最好的辦法就是通過不完全恢復,可以保證數據庫的一致性,但是這種辦法要求在歸檔方式下,并且有可用的備份
??? B. 通過強制性恢復,但是可能導致數據庫不一致。
??? B. 通過強制性恢復,但是可能導致數據庫不一致。
?
下面分別用來說明這兩種恢復方法
1.通過備份來恢復
?
1、關閉數據庫,刪除當前Logfile,再打開數據庫時,遇到一個類似的錯誤
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
Database dismounted.
ORACLE instance shut down.
?
C:>del D:\oracle\oradata\dodo\REDO01.LOG
?
SQL> startup;
ORACLE instance started.
ORACLE instance started.
Total System Global Area? 135338868 bytes
Fixed Size?????????????????? 453492 bytes
Variable Size???????????? 109051904 bytes
Database Buffers?????????? 25165824 bytes
Redo Buffers???????????????? 667648 bytes
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO01.LOG'
Fixed Size?????????????????? 453492 bytes
Variable Size???????????? 109051904 bytes
Database Buffers?????????? 25165824 bytes
Redo Buffers???????????????? 667648 bytes
Database mounted.
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO01.LOG'
報警日志中的描述如下:
?
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO01.LOG'
ORA-27041: unable to open file
OSD-04002: 無法打開文件
O/S-Error: (OS 2) 系統找不到指定的文件。
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO01.LOG'
ORA-27041: unable to open file
OSD-04002: 無法打開文件
O/S-Error: (OS 2) 系統找不到指定的文件。
?
2、查看V$log,發現是當前日志
?
SQL> select group#,sequence#,archived,status from v$log;
??? GROUP#? SEQUENCE# ARCHIVED?? STATUS
---------- ---------- ---------- ----------------
???????? 1????????? 1 NO???????? CURRENT
???????? 2????????? 0 YES??????? UNUSED
???????? 3????????? 0 YES??????? UNUSED
---------- ---------- ---------- ----------------
???????? 1????????? 1 NO???????? CURRENT
???????? 2????????? 0 YES??????? UNUSED
???????? 3????????? 0 YES??????? UNUSED
3、發現clear不成功
SQL> alter database clear unarchived logfile group 1;
alter database clear unarchived logfile group 1
*
ERROR at line 1:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO01.LOG'
ORA-27041: unable to open file
OSD-04002: 無法打開文件
O/S-Error: (OS 2) 系統找不到指定的文件。
*
ERROR at line 1:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO01.LOG'
ORA-27041: unable to open file
OSD-04002: 無法打開文件
O/S-Error: (OS 2) 系統找不到指定的文件。
4、拷貝有效的數據庫的全備份,并不完全恢復數據庫
?
可以采用獲取最近的SCN的辦法用until scn恢復或用until cnacel恢復
recover database until cancel
先選擇auto,盡量恢復可以利用的歸檔日志,然后重新
recover database until cancel
這次輸入cancel,完成不完全恢復,也就是說恢復兩次。
SQL> recover database until cancel;
Auto
……
SQL> recover database until cancel;
Cancel;
5、利用alter database open resetlogs打開數據庫
?
說明:
1、這種辦法恢復的數據庫是一致的不完全恢復,會丟失當前聯機日志中的事務數據
2、這種方法適合于歸檔數據庫并且有可用的數據庫全備份。
3、恢復成功之后,記得再做一次數據庫的全備份。
4、建議聯機日志文件一定要實現鏡相在不同的磁盤上,避免這種情況的發生,因為任何數據的丟失對于生產來說都是不容許的。
2、這種方法適合于歸檔數據庫并且有可用的數據庫全備份。
3、恢復成功之后,記得再做一次數據庫的全備份。
4、建議聯機日志文件一定要實現鏡相在不同的磁盤上,避免這種情況的發生,因為任何數據的丟失對于生產來說都是不容許的。
?
?
2.如果沒有備份,進行強制性恢復
1、打開數據庫,會遇到一個類似的錯誤
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO01.LOG'
ORA-27041: unable to open file
OSD-04002: 無法打開文件
O/S-Error: (OS 2) 系統找不到指定的文件。
2、查看V$log,發現是當前日志
SQL> select group#,sequence#,archived,status from v$log;
??? GROUP#? SEQUENCE# ARCHIVED?? STATUS
---------- ---------- ---------- ----------------
???????? 1????????? 1 NO???????? CURRENT
???????? 2????????? 0 YES??????? UNUSED
???????? 3????????? 0 YES??????? UNUSED
---------- ---------- ---------- ----------------
???????? 1????????? 1 NO???????? CURRENT
???????? 2????????? 0 YES??????? UNUSED
???????? 3????????? 0 YES??????? UNUSED
3、發現clear不成功
SQL> alter database clear unarchived logfile group 1;
alter database clear unarchived logfile group 1
*
ERROR at line 1:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO01.LOG'
ORA-27041: unable to open file
OSD-04002: 無法打開文件
O/S-Error: (OS 2) 系統找不到指定的文件。
*
ERROR at line 1:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: 'D:\ORACLE\ORADATA\DODO\REDO01.LOG'
ORA-27041: unable to open file
OSD-04002: 無法打開文件
O/S-Error: (OS 2) 系統找不到指定的文件。
4、把數據庫down掉
SQL>shutdown immediate
5、在spfile中加入如下參數
_allow_resetlogs_corruption=TRUE
6、重新啟動數據庫,利用until cancel恢復
SQL>recover database until cancel;
Cancel
如果出錯,不再理會,發出:
SQL>alter database open resetlogs;
7、數據庫被打開后,馬上執行一個full export
8、shutdown數據庫,去掉_all_resetlogs_corrupt參數
9、重建庫
10、import并完成恢復
11、建議執行一下ANALYZE TABLE ...VALIDATE STRUCTURE CASCADE;
?
說明:
1、該恢復方法是沒有辦法之后的恢復方法,一般情況下建議不要采用,因為該方法可能導致數據庫的不一致
2、該方法也丟失數據,但是丟失的數據沒有上一種方法的數據多,主要是未寫入數據文件的已提交或未提交數據。
3、建議成功后嚴格執行以上的7到11步,完成數據庫的檢查與分析
4、全部完成后做一次數據庫的全備份
5、建議聯機日志文件一定要實現鏡相在不同的磁盤上,避免這種情況的發生,因為任何數據的丟失對于生產來說都是不容許的。
?
?
?