1、不一樣場景控制文件損壞時的恢復方法linux
場景sql |
恢復方法數據庫 |
恢復條件session |
|
其中一個控制文件損壞oracle |
1.1 拷貝冗餘的控制文件app |
1、具備多路冗餘控制文件鏡像 |
|
1.2 修改control_files參數去除損壞文件this |
同上、但不推薦該方法進行恢復spa |
||
全部的控制文件損壞rest |
有備份 |
2.1 經過rman備份控制文件進行徹底恢復 |
1、經過rman備份了控制文件 |
2.2 經過rman備份控制文件進行不徹底恢復 |
1、經過rman備份了控制文件 |
||
2.3 經過trace備份控制文件進行徹底恢復 |
1、經過trace備份了控制文件 |
||
2.4 經過trace備份控制文件進行不徹底恢復 |
1、經過trace備份了控制文件 |
||
無備份 |
2.5 經過手工重建控制文件進行恢復(noresetlogs) |
1、無有效的備份控制文件 |
|
2.6 經過手工重建控制文件進行恢復(resetlogs) |
1、無有效的備份控制文件 |
||
2.7 經過SNAPSHOT CONTROLFILE文件進行恢復 |
此處爲記錄一個恢復控制文件的方法(不常使用) |
2、不一樣場景控制文件損壞的恢復思路及演示
2.1 其中一個控制文件損壞恢復思路
A. shutdown abort 關閉數據庫(控制文件損壞後不能正常關閉數據庫,只能使用abort強制關閉)
B. 拷貝其中一個無缺的控制文件(推薦)或者修改control_files參數去除損壞文件(不推薦)
C. startup啓動數據庫
2.2 其中一個控制文件損壞恢復演示
SQL> show parameter control_files NAME TYPE VALUE ---------------------------------------------------------- ------------------------------ control_files string /u/app/oracle/oradata/racdg/control01.ctl,/u/app/oracle/ora data/racdg/control02.ctl SQL> !mv/u/app/oracle/oradata/racdg/control02.ctl /u/app/oracle/oradata/racdg/control02.ctl.bak SQL> shutdown immediate; --無正常關閉數據庫,須要abort強制關閉 ORA-00210: cannot open the specifiedcontrol file ORA-00202: control file:'/u/app/oracle/oradata/racdg/control02.ctl' ORA-27041: unable to open file Linux-x86_64 Error: 2: No such file ordirectory Additional information: 3 SQL> shutdown abort; --只能shutdown abort強制關閉 ORACLE instance shut down. SQL> startup; --啓動數據庫 ORACLE instance started. ORA-00205: error in identifying controlfile, check alert log for more info --啓動報錯,找不到指定的控制文件,在告警日誌文件alert_sid.log中能夠看到以下報錯: ORA-00210: cannot open the specifiedcontrol file ORA-00202: control file:'/u/app/oracle/oradata/racdg/control02.ctl' SQL> !pwd /u/app/oracle/oradata/racdg SQL> !cp control01.ctl control02.ctl --或者: SQL>alter system set control_files=’ /u/app/oracle/oradata/racdg/control01.ctl’scope=both; --不建議,由於這樣一來就只剩一份控制文件了,起不到冗餘做用,再這次發生丟失,恢復就變得麻煩了。 SQL> alter database mount; Database altered.
使用ASM存放控制文件,其中一個控制文件損壞恢復演示
SQL> show parameter control_files; NAME TYPE VALUE ----------------------------------------------- ------------------------------ control_files string +DATA/racdb/controlfile/current.256.935676497, +DATA/racdb/c ontrolfile/current.478.957977179 SQL> shutdown abort; --這裏我是爲了演示才直接關閉數據的,由於在線狀況下asm的文件是不能刪除的 ORACLE instance shut down. SQL> !su - grid -c "asmcmd -p rm +DATA/racdb/controlfile/current.478.957977179" Password: SQL> startup nomount; --將數據庫啓動到nomount狀態 ORACLE instance started. SQL> !rman target / --這裏使用rman來恢復,固然使用以前的兩種方法拷貝和去除也是能夠的 Recovery Manager: Release 11.2.0.4.0 -Production on Sat Oct 21 16:53:15 2017 Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved. connected to target database: RACDB (notmounted) RMAN> restore controlfile from'+DATA/racdb/controlfile/current.256.935676497'; --其實這裏就是拷貝的方式 Starting restore at 2017/10/21 16:54:18 using target database control file insteadof recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=143 instance=racdb1device type=DISK channel ORA_DISK_1: copied control filecopy output filename=+DATA/racdb/controlfile/current.256.935676497 output filename=+DATA/racdb/controlfile/current.478.957977659 Finished restore at 2017/10/21 16:54:22 RMAN> sql 'alter database mount'; sql statement: alter database mount released channel: ORA_DISK_1
說明一下,這裏我分了文件系統和ASM存儲存放控制文件的狀況,其恢復原理都是同樣的,不管是在線或者關閉數據庫後損壞了其中部分控制文件,恢復方法都是同樣的。
2.3全部的控制文件損壞,有備份場景
2.3.1經過rman備份控制文件進行徹底恢復思路
A. 若在線損壞,shutdown abort關閉數據庫;若關閉數據庫後損壞,到第二步
B. startup nomount啓動數據庫到nomount狀態。
C. 使用rman從備份中恢復控制文件:restorecontrolfile from '/path';
D. alter database mount;啓動數據庫到mount狀態
E. recover database using backupcontrolfile until cancel; 應用歸檔文件
F. 再執行recover databaseusing backup controlfile; 應用未歸檔的redo文件
G. alter database open resetlogs; 以resetlogs的方式打開數據庫
2.3.2經過rman備份控制文件進行徹底恢復演示
SQL> show parameter control_files; NAME TYPE VALUE ---------------------------------------------------------- ------------------------------ control_files string /u/app/oracle/oradata/racdg/control01.ctl,/u/app/oracle/ora data/racdg/control02.ctl, /u/app/oracle/oradata/racdg/control03 .ctl SQL> !rm control01.ctl control02.ctlcontrol03.ctl --刪除全部的控制文件,模擬控制文件丟失 SQL> shutdown abort; --強制關閉數據庫 ORACLE instance shut down. SQL> startup; --啓動數據到nomount狀態 ORACLE instance started. ORA-00205: error in identifying controlfile, check alert log for more info --報錯,同時查看告警日誌,會發現全部控制文件都已經丟失。 SQL> !rman target / --此前有作過RMAN控制文件備份,使用rman進行恢復 Recovery Manager: Release 11.2.0.4.0 -Production on Sat Oct 21 17:24:11 2017 Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved. connected to target database: RACDG (notmounted) RMAN> restore controlfile from'/u/app/oracle/zwdir/RACDG_20171021_0fshj32i_1_1.ctl'; --恢復控制文件 Starting restore at 2017/10/21 17:24:57 using target database control file insteadof recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=135 devicetype=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete,elapsed time: 00:00:03 output filename=/u/app/oracle/oradata/racdg/control01.ctl output filename=/u/app/oracle/oradata/racdg/control02.ctl output filename=/u/app/oracle/oradata/racdg/control03.ctl Finished restore at 2017/10/21 17:25:01 RMAN> sql 'alter database mount'; --將數據庫啓動到mount狀態 sql statement: alter database mount released channel: ORA_DISK_1 RMAN> exit Recovery Manager complete. SQL> recover database using backupcontrolfile until cancel; ORA-00279: change 1041001 generated at10/21/2017 16:04:25 needed for thread 1 ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_6_957480185.dbf ORA-00280: change 1041001 for thread 1 isin sequence #6 Specify log: {<RET>=suggested |filename | AUTO | CANCEL} auto ORA-00279: change 1041011 generated at10/21/2017 16:20:36 needed for thread 1 ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_7_957480185.dbf ORA-00280: change 1041011 for thread 1 isin sequence #7 ORA-00278: log file'/u/app/oracle/oradata/arch/1_6_957480185.dbf' no longer needed for thisrecovery ORA-00279: change 1041019 generated at10/21/2017 16:20:36 needed for thread 1 ORA-00289: suggestion : /u/app/oracle/oradata/arch/1_8_957480185.dbf ORA-00280: change 1041019 for thread 1 isin sequence #8 ORA-00278: log file'/u/app/oracle/oradata/arch/1_7_957480185.dbf' no longer needed for thisrecovery ORA-00308: cannot open archived log'/u/app/oracle/oradata/arch/1_8_957480185.dbf' ORA-27037: unable to obtain file status --缺乏序號爲8的歸檔,這是由於redo還存在歸檔未切換 Linux-x86_64 Error: 2: No such file ordirectory Additional information: 3 ORA-01547: warning: RECOVER succeeded butOPEN RESETLOGS would get error below ORA-01194: file 1 needs more recovery to beconsistent ORA-01110: data file 1:'/u/app/oracle/oradata/racdg/system01.dbf' SQL> selecta.group#,a.sequence#,a.archived,a.status,b.member from v$log a,v$logfile bwhere a.group#=b.group#; GROUP# SEQUENCE# ARCHIV STATUS MEMBER ---------- ---------- ------------------------------------------------------------------------------------------------ 1 4 YES INACTIVE /u/app/oracle/oradata/racdg/redo01.log 3 6NO CURRENT /u/app/oracle/oradata/racdg/redo03.log --當前未歸檔的redo文件 2 5 YES INACTIVE /u/app/oracle/oradata/racdg/redo02.log SQL> recover database using backupcontrolfile; --再次執行,應用未歸檔的redo文件 ORA-00279: change 1041019 generated at10/21/2017 16:20:36 needed for thread 1 ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_8_957480185.dbf ORA-00280: change 1041019 for thread 1 isin sequence #8 --這裏看到未歸檔的redo文件,歸檔序號爲6,而這裏須要恢復序列爲8的歸檔,因此應該是應用/u/app/oracle/oradata/racdg/redo02.log這個redo文件。 Specify log: {<RET>=suggested |filename | AUTO | CANCEL} /u/app/oracle/oradata/racdg/redo02.log Log applied. Media recovery complete. SQL> alter database open resetlogs; --以resetlogs的方式打開數據庫 Database altered.
resetlogs與noresetlogs的區別說明:
norestlogs控制文件的scn是來自當前日誌的highscn,而resetlogs控制文件的scn是來自數據文件。
noresetlogs會繼續使用已經存在,且有效的logfiles,而resetlogs會初始化logs,重置log sequence號,建立一個新的incarnation
2.3.3經過rman備份控制文件進行不徹底恢復思路
A. 若在線損壞,shutdown abort關閉數據庫;若關閉數據庫後損壞,到第二步
B. startup nomount啓動數據庫到nomount狀態。
C. 使用rman從備份中恢復控制文件:restorecontrolfile from '/path';
D. alter database mount;啓動數據庫到mount狀態
E. recover database using backupcontrolfile until cancel; 應用盡量多的歸檔文件
G. 若丟失redo文件:
shutdown immediate並啓動到startupnomount狀態
alter database backup controlfile to traceas ‘/u/app/oracle/zwdir/controlfile.sql’; 生成建立控制文件的腳本
使用resetlogs方式建立控制文件
若未歸檔的redo文件可用:直接recover database,選用未歸檔的redo應用,alter database open resetlogs方式打開數據庫
若未歸檔的redo文件不可用:設置隱含參數_allow_resetlogs_corruption=true跳過一致性檢查,alterdatabase open resetlogs方式打開數據庫
F. 若丟失歸檔文件:
shutdown immediate並啓動到startupnomount狀態
alter database backup controlfile to traceas ‘/u/app/oracle/zwdir/controlfile.sql’; 生成建立控制文件的腳本
使用noresetlogs方式建立控制文件
recover database using backup controlfileuntil cancel; 應用redo文件
alter database open resetlogs; 以resetlogs的方式打開數據庫
若備份控制文件以後,數據庫結構發生了變化,如新增了表空間或數據文件,須要進行不徹底恢復
2.3.4經過rman備份控制文件進行不徹底恢復演示
這裏模擬演示模擬備份控制文件以後,新增表空間,歸檔文件所有丟失的不徹底恢復的狀況,丟失redo的狀況,請看下一節「oracle數據庫恢復系列之redo文件恢復」
[oracle@iscsi-asmzwdir]$ rman target / RMAN> backup current controlfile format'/u/app/oracle/zwdir/use_this_%U.ctl' tag='ctl'; --備份當前的控制文件 Starting backup at 2017/10/29 17:03:31 using target database control file insteadof recovery catalog piecehandle=/u/app/oracle/zwdir/use_this_08si88j3_1_1.ctl tag=CTL comment=NONE channel ORA_DISK_1: backup set complete,elapsed time: 00:00:01 Finished backup at 2017/10/29 17:03:33 [oracle@iscsi-asm racdg]$ sqlplus / assysdba SQL> create tablespace t_del_archdatafile '/u/app/oracle/oradata/racdg/t_del_arch01.dbf' size 20m; --新增表空間 Tablespace created. SQL> create user t_arch identified bypassword default tablespace t_del_arch; --新建用戶 User created. SQL> grant resource,connect to t_arch; --受權 Grant succeeded. SQL> alter system switch logfile; --切換歸檔日誌 System altered. SQL> create table t_arch.t1 as select *from dba_objects where rownum<1000; --新建表,並插入數據 Table created. SQL> alter system switch logfile; --切換歸檔日誌 System altered. SQL> select count(*) from t_arch.t1; COUNT(*) ---------- 999 SQL> insert into t_arch.t1 select * fromt_arch.t1; --新增數據 999 rows created. SQL> commit; Commit complete. SQL> alter system switch logfile; --切換日誌 System altered. SQL> select count(*) from t_arch.t1; --記錄當前的數據,用做恢復的數據對比 COUNT(*) ---------- 1998 SQL> archive log list; --當前歸檔的序號 Database log mode Archive Mode Automatic archival Enabled Archive destination /u/app/oracle/oradata/arch Oldest online log sequence 5 Next log sequence to archive 7 Current log sequence 7 SQL> shutdown abort; --關閉數據庫 ORACLE instance shut down. SQL> !rm control01.ctl control02.ctl --模擬控制文件丟失 SQL> !mv/u/app/oracle/oradata/arch/*.dbf /u/app/oracle/oradata/arch/tmp --模擬歸檔文件所有丟失 SQL> startup nomount; ORACLE instance started. SQL> !rman target / Recovery Manager: Release 11.2.0.4.0 -Production on Sun Oct 29 17:19:33 2017 Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved. connected to target database: RACDG (notmounted) RMAN> restore controlfile from'/u/app/oracle/zwdir/use_this_08si88j3_1_1.ctl'; --經過舊備份控制文件進行恢復 Starting restore at 2017/10/29 17:19:44 using target database control file insteadof recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=10 device type=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete,elapsed time: 00:00:01 output filename=/u/app/oracle/oradata/racdg/control01.ctl output filename=/u/app/oracle/oradata/racdg/control02.ctl Finished restore at 2017/10/29 17:19:46 RMAN> exit Recovery Manager complete. SQL> alter database mount; Database altered. SQL> alter database backup controlfileto trace as '/u/app/oracle/zwdir/controlfile.sql'; Database altered. --此時歸檔文件已經丟失了,沒法經過應用歸檔文件進行恢復,因此經過trc新建控制文件的方式進行恢復。 SQL> shutdown abort; --關閉數據庫 ORACLE instance shut down. SQL> STARTUP NOMOUNT --啓動到nomount狀態 ORACLE instance started. SQL> CREATE CONTROLFILE REUSE DATABASE"RACDG" NORESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 '/u/app/oracle/oradata/racdg/redo01.log' SIZE 50M BLOCKSIZE 512, GROUP 2 '/u/app/oracle/oradata/racdg/redo02.log' SIZE 50M BLOCKSIZE 512, GROUP 3 '/u/app/oracle/oradata/racdg/redo03.log' SIZE 50M BLOCKSIZE 512 -- STANDBY LOGFILE DATAFILE '/u/app/oracle/oradata/racdg/system01.dbf', '/u/app/oracle/oradata/racdg/sysaux01.dbf', '/u/app/oracle/oradata/racdg/undotbs01.dbf', '/u/app/oracle/oradata/racdg/users01.dbf' CHARACTER SET WE8MSWIN1252 ; --以上新建控制文件的內容就是經過/u/app/oracle/zwdir/controlfile.sql裏面的記錄來進行新建的,裏面共有兩種方式,一種是noresetlogs,另外一種是resetlogs的方式。這裏由於redo文件是沒有丟失的,因此使用nosesetlogs的方式。 Control file created. SQL> selectb.sequence#,a.member,b.status from v$logfile a, v$log b wherea.group#=b.group#; --查詢redo信息 SEQUENCE# MEMBER STATUS ------------------------------------------------------- -------------------------------- 7 /u/app/oracle/oradata/racdg/redo01.log CURRENT 5 /u/app/oracle/oradata/racdg/redo02.log INACTIVE 6 /u/app/oracle/oradata/racdg/redo03.log INACTIVE SQL> select file#,name,status fromv$datafile; --查詢數據文件信息,此時數據文件都是須要恢復 FILE# NAME STATUS ------------------------------------------------------- -------------- 1 /u/app/oracle/oradata/racdg/system01.dbf SYSTEM 2 /u/app/oracle/oradata/racdg/sysaux01.dbf RECOVER 3 /u/app/oracle/oradata/racdg/undotbs01.dbf RECOVER 4 /u/app/oracle/oradata/racdg/users01.dbf RECOVER SQL> recover database using backupcontrolfile until cancel; --恢復數據庫,應用redo日誌 ORA-00279: change 932267 generated at10/29/2017 17:07:56 needed for thread 1 ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_6_958668721.dbf ORA-00280: change 932267 for thread 1 is insequence #6 Specify log: {<RET>=suggested |filename | AUTO | CANCEL} /u/app/oracle/oradata/racdg/redo03.log ORA-00279: change 932300 generated at10/29/2017 17:09:10 needed for thread 1 ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_7_958668721.dbf ORA-00280: change 932300 for thread 1 is insequence #7 ORA-00278: log file'/u/app/oracle/oradata/racdg/redo03.log' no longer needed for this recovery Specify log: {<RET>=suggested |filename | AUTO | CANCEL} /u/app/oracle/oradata/racdg/redo01.log Log applied. Media recovery complete. SQL> alter database open resetlogs; --以resetlogs的方式打開數據庫 Database altered. SQL> select file#,name,status fromv$datafile; --查看數據文件的狀態,備份控制文件以後的表空間對應的數據文件須要進一步恢復。 FILE# NAME STATUS -------------------------------------------------------------- -------------- 1 /u/app/oracle/oradata/racdg/system01.dbf SYSTEM 2 /u/app/oracle/oradata/racdg/sysaux01.dbf ONLINE 3 /u/app/oracle/oradata/racdg/undotbs01.dbf ONLINE 4 /u/app/oracle/oradata/racdg/users01.dbf ONLINE 5/u/app/oracle/product/11.2.0/db_1/dbs/MISSING00005RECOVER SQL> alter database datafile 5 offline; --先將數據文件offline Database altered. SQL>alter database rename file'/u/app/oracle/product/11.2.0/db_1/dbs/MISSING00005' to'/u/app/oracle/oradata/racdg/t_del_arch01.dbf'; --重命名數據文件 Database altered. SQL> alter tablespace t_del_arch online; ---嘗試將表空間online,報錯 alter tablespace t_del_arch online * ERROR at line 1: ORA-01190: control file or data file 5 isfrom before the last RESETLOGS ORA-01110: data file 5: '/u/app/oracle/oradata/racdg/t_del_arch01.dbf' SQL> alter system set"_allow_resetlogs_corruption"=true scope=spfile; --修改參數,忽略SCN一致性校驗 System altered. SQL> startup force; --再將數據庫從新啓動 ORACLE instance started. Total System Global Area 830930944 bytes Fixed Size 2257800 bytes Variable Size 536874104 bytes Database Buffers 285212672 bytes Redo Buffers 6586368 bytes Database mounted. Database opened. SQL> selectts#,file#,name,status,checkpoint_change# from v$datafile; --查詢數據文件的狀況 TS# FILE# NAME STATUS CHECKPOINT_CHANGE# ---------- ---------- ----------------------------------------------------------- ------------------ 0 1 /u/app/oracle/oradata/racdg/system01.dbf SYSTEM 953040 1 2 /u/app/oracle/oradata/racdg/sysaux01.dbf ONLINE 953040 2 3 /u/app/oracle/oradata/racdg/undotbs01.dbf ONLINE 953040 4 4 /u/app/oracle/oradata/racdg/users01.dbf ONLINE 953040 6 5/u/app/oracle/oradata/racdg/t_del_arch01.dbf RECOVER 0 SQL> alter session set events 'immediatetrace name adjust_scn level 1'; --經過設置adjust_scn使數據文件的CHECKPOINT_CHANGE#一致 Session altered. SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount; --啓動到mount狀態 ORACLE instance started. Total System Global Area 830930944 bytes Fixed Size 2257800 bytes Variable Size 536874104 bytes Database Buffers 285212672 bytes Redo Buffers 6586368 bytes Database mounted. SQL> recover until cancel; --恢復數據庫,注意這裏不是usingcontrolfile的方式 Media recovery complete. SQL> alter database datafile 2,3,4,5online; ---將全部的數據文件online,記得千萬不用漏了 Database altered. SQL> alter database open resetlogs; --以resetlogs的方式打開數據庫 Database altered. SQL> selectts#,file#,name,status,checkpoint_change# from v$datafile; --查詢數據文件的狀況 TS# FILE#NAME STATUS CHECKPOINT_CHANGE# ---------- ------------------------------------------------------- -------------- ------------------ 0 1 /u/app/oracle/oradata/racdg/system01.dbf SYSTEM 953040 1 2 /u/app/oracle/oradata/racdg/sysaux01.dbf ONLINE 953040 2 3/u/app/oracle/oradata/racdg/undotbs01.dbf ONLINE 953040 4 4 /u/app/oracle/oradata/racdg/users01.dbf ONLINE 953040 6 5 /u/app/oracle/oradata/racdg/t_del_arch01.dbf ONLINE 953040 SQL> select count(*) from t_arch.t1; --對比數據,發現存在數據丟失,出現這種狀況,只能把損失降到最小 COUNT(*) ---------- 999 SQL> alter tablespace temp add tempfile'/u/app/oracle/oradata/racdg/temp01.dbf' reuse; --重建temp表空間 Database altered.
2.3.4經過trace備份控制文件進行徹底恢復思路
A.備份控制文件到trace:alterdatabase backup controlfile to trace as '/path/controlfile.sql';
B.若在線損壞,直接alterdatabase backup controlfile to 'file';以後重啓數據庫
C.若關閉數據庫後損壞,shutdownabort關閉數據庫後,startup nomount啓動數據庫到nomount狀態
D.使用備份到trace裏建立控制文件的語句,以noresetlogs方式建立控制文件
E.recover database恢復數據庫,恢復完後經過alterdatabase open打開數據庫
F.重建temp表空間:altertablespace temp add tempfile '/path/temp01.dbf' reuse;
2.3.5經過trace備份控制文件進行徹底恢復演示
oracle數據庫提供了多種對控制文件的備份方式:rman、alterdatabase backup controlfile to trace、alter databasebackup controlfile to filename 這裏只演示在線損壞時經過alter database backup controlfile to filename 的恢復,由於經過trace備份的恢復演示在「2.3.4經過rman備份控制文件進行不徹底恢復演示」章節已經寫了。
SQL> select open_mode from v$database; OPEN_MODE ---------------------------------------- READ WRITE SQL> !rm control01.ctl control02.ctl --這種狀況主要是數據庫還在運行狀態,手賤誤刪的恢復 SQL> alter database backup controlfileto '/u/app/oracle/oradata/racdg/control01.ctl.bak'; --備份成二進制文件 Database altered. SQL> shutdown abort; ORACLE instance shut down. SQL> !cp control01.ctl.bak control01.ctl–直接拷貝使用 SQL> !cp control01.ctl.bak control02.ctl SQL> startup mount; --啓動到mount狀態 ORACLE instance started. Total System Global Area 830930944 bytes Fixed Size 2257800 bytes Variable Size 536874104 bytes Database Buffers 285212672 bytes Redo Buffers 6586368 bytes Database mounted. SQL> selecta.group#,a.sequence#,a.archived,a.status,b.member from v$log a,v$logfile bwhere a.group#=b.group#; GROUP# SEQUENCE# ARCHIV STATUS MEMBER ---------- ---------- --------------------- ---------------------------------------- 1 1 NO CURRENT /u/app/oracle/oradata/racdg/redo01.log 3 0 YES UNUSED /u/app/oracle/oradata/racdg/redo03.log 2 0 YES UNUSED /u/app/oracle/oradata/racdg/redo02.log SQL> recover database using backupcontrolfile until cancel; ORA-00279: change 932699 generated at10/31/2017 19:25:50 needed for thread 1 ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_1_958850748.dbf ORA-00280: change 932699 for thread 1 is insequence #1 Specify log: {<RET>=suggested |filename | AUTO | CANCEL} /u/app/oracle/oradata/racdg/redo01.log –應用redo文件 Log applied. Media recovery complete. SQL> alter database open resetlogs; --以resetlogs的方式開啓數據庫 Database altered.
2.3.6經過trace備份控制文件進行不徹底恢復思路
A.備份控制文件到trace:alterdatabase backup controlfile to trace as '/path/controlfile.sql';
B.shutdown abort關閉數據庫後,startupnomount啓動數據庫到nomount狀態
C. 若丟失redo文件,歸檔未丟失:
使用備份到trace裏建立控制文件的語句,以resetlogs方式建立控制文件
alter database mount;啓動數據庫mount狀態
若未歸檔的redo文件可用:直接recover database,選用未歸檔的redo應用,alter database open resetlogs方式打開數據庫
若未歸檔的redo文件不可用:設置隱含參數_allow_resetlogs_corruption=true跳過一致性檢查,alterdatabase open resetlogs方式打開數據庫
D. 若丟失歸檔文件,redo未丟失:
使用備份到trace裏建立控制文件的語句,以resetlogs方式建立控制文件
alter database mount;啓動數據庫mount狀態
recover database using backup controlfileuntil cancel; 應用redo文件
alter database open resetlogs; 以resetlogs的方式打開數據庫
若備份控制文件以後,數據庫結構發生了變化,如新增了表空間或數據文件,須要進行不徹底恢復
E. 若歸檔文件和redo文件都丟失:
步驟與若丟失歸檔文件,redo未丟失的恢復步驟同樣,主要是以resetlogs方式建立控制文件
F.重建temp表空間:altertablespace temp add tempfile '/path/temp01.dbf' reuse;
2.3.7經過trace備份控制文件進行不徹底恢復演示
請參照「2.3.4經過rman備份控制文件進行不徹底恢復演示」,主要注意如下幾點:
A.trace備份的控制文件並非實時的備份,可能不是最新的,備份以後數據庫結構可能發生了變化
B.對於此類恢復必定須要謹慎,恢復完以後立刻作個全備,儘可能將數據丟失下降到最小。
2.4全部的控制文件損壞,無備份場景
2.4.1經過手工重建控制文件進行恢復(noresetlogs)思路
A.shutdown abort關閉數據庫後,startupnomount啓動數據庫到nomount狀態
B.手工構造控制文件,以noresetlogs方式
C. alter database mount;啓動數據庫到mount狀態
D. recover database using backupcontrolfile until cancel; 應用歸檔文件
E. 再執行recover databaseusing backup controlfile; 應用未歸檔的redo文件
F. alter database open resetlogs; 以resetlogs的方式打開數據庫
2.4.2經過手工重建控制文件進行恢復(resetlogs)思路
A.shutdown abort關閉數據庫後,startupnomount啓動數據庫到nomount狀態
B.手工構造控制文件,以resetlogs方式
C. alter database mount;啓動數據庫到mount狀態
D. recover database using backupcontrolfile until cancel; 應用歸檔文件(不考慮歸檔文件丟失)
E. 再執行recover databaseusing backup controlfile; 應用未歸檔的redo文件(不考慮redo文件丟失)
F. alter database open resetlogs; 以resetlogs的方式打開數據庫
2.4.3經過手工重建控制文件進行恢復(resetlogs)演示
這裏不做很是具體的演示了,前面的章節已經演示過了,就說明一下須要注意的幾點:
由於是手動構建,因此在構建的過程當中必定要仔細檢查數據庫清除數據庫有多少文件,構建腳本以下:
CREATE CONTROLFILE REUSE DATABASE"RACDG" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 '/u/app/oracle/oradata/racdg/redo01.log' SIZE 50M BLOCKSIZE 512, GROUP 2 '/u/app/oracle/oradata/racdg/redo02.log' SIZE 50M BLOCKSIZE 512, GROUP 3 '/u/app/oracle/oradata/racdg/redo03.log' SIZE 50M BLOCKSIZE 512 -- STANDBY LOGFILE DATAFILE '/u/app/oracle/oradata/racdg/system01.dbf', '/u/app/oracle/oradata/racdg/sysaux01.dbf', '/u/app/oracle/oradata/racdg/undotbs01.dbf', '/u/app/oracle/oradata/racdg/users01.dbf', '/u/app/oracle/oradata/racdg/t_del_arch01.dbf' CHARACTER SET WE8MSWIN1252;
必定要都存放文件的路徑下去ls –ltr列一下有哪些文件,千萬不要把某個文件漏了。
B. 手動構建控制文件是存在必定的數據丟失風險的,必定得細心,細心,再細心。
2.4.4經過SNAPSHOTCONTROLFILE文件進行恢復思路
A.shutdown abort關閉數據庫後,startupnomount啓動數據庫到nomount狀態
B.直接拷貝snapshot controlfile成control file或經過rman恢復:restore controlfile from '$ORACLE_HOME/dbs/snapcf_@.f';
C. alter database mount;啓動數據庫到mount狀態
D. recover database using backupcontrolfile until cancel; 應用歸檔文件(不考慮歸檔文件丟失)
E. 再執行recover databaseusing backup controlfile; 應用未歸檔的redo文件(不考慮redo文件丟失)
F. alter database open resetlogs; 以resetlogs的方式打開數據庫
2.4.5經過SNAPSHOTCONTROLFILE文件進行恢復演示
RMAN> show snapshot controlfile name; --查看快照控制文件配置 using target database control file insteadof recovery catalog RMAN configuration parameters for databasewith db_unique_name RACDG are: CONFIGURE SNAPSHOT CONTROLFILE NAME TO'/u/app/oracle/product/11.2.0/db_1/dbs/snapcf_racdg.f'; # default --若是是RAC,通常建議將該配置文件配置在ASM或ACFS等共享存儲上。 SQL> !rm control01.ctl control02.ctl --模擬控制文件丟失 SQL> shutdown abort; --強制關閉數據庫 ORACLE instance shut down. SQL> startup nomount; --啓動數據庫到mount狀態 ORACLE instance started. SQL> !cp/u/app/oracle/product/11.2.0/db_1/dbs/snapcf_racdg.f control01.ctl --直接拷貝快照控制文件 SQL> !cp/u/app/oracle/product/11.2.0/db_1/dbs/snapcf_racdg.f control02.ctl SQL> !ls -ltr control*.ctl -rw-r----- 1 oracle oinstall 9748480Nov 1 18:48 control01.ctl -rw-r----- 1 oracle oinstall 9748480Nov 1 18:48 control02.ctl --或者使用RMAN進行恢復:restorecontrolfile from ‘/u/app/oracle/product/11.2.0/db_1/dbs/snapcf_racdg.f’; SQL> alter database mount; --啓動數據庫到mount狀態 Database altered. SQL> recover database using backupcontrolfile until cancel; --應該歸檔文件 ORA-00279: change 948557 generated at10/31/2017 22:00:44 needed for thread 1 ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_2_958851405.dbf ORA-00280: change 948557 for thread 1 is insequence #2 Specify log: {<RET>=suggested |filename | AUTO | CANCEL} auto ORA-00308: cannot open archived log'/u/app/oracle/oradata/arch/1_4_958851405.dbf' ORA-27037: unable to obtain file status Linux-x86_64 Error: 2: No such file or directory Additional information: 3 ORA-00308: cannot open archived log'/u/app/oracle/oradata/arch/1_4_958851405.dbf' ORA-27037: unable to obtain file status Linux-x86_64 Error: 2: No such file ordirectory Additional information: 3 ORA-01547: warning: RECOVER succeeded butOPEN RESETLOGS would get error below ORA-01194: file 1 needs more recovery to beconsistent ORA-01110: data file 1:'/u/app/oracle/oradata/racdg/system01.dbf' SQL> selecta.group#,a.sequence#,a.archived,a.status,b.member from v$log a,v$logfile bwhere a.group#=b.group#; GROUP# SEQUENCE# ARCHIV STATUS MEMBER ---------- ---------- -------------------------- ------------------------------------------------ 1 1 YES INACTIVE /u/app/oracle/oradata/racdg/redo01.log 3 0 YES UNUSED /u/app/oracle/oradata/racdg/redo03.log 2 2 NO CURRENT /u/app/oracle/oradata/racdg/redo02.log SQL> recover database using backupcontrolfile until cancel; --應用redo文件 ORA-00279: change 948625 generated at11/01/2017 18:41:13 needed for thread 1 ORA-00289: suggestion :/u/app/oracle/oradata/arch/1_4_958851405.dbf ORA-00280: change 948625 for thread 1 is insequence #4 Specify log: {<RET>=suggested |filename | AUTO | CANCEL} /u/app/oracle/oradata/racdg/redo01.log Log applied. Media recovery complete. SQL> alter database open resetlogs; --以resetlogs的方式開啓數據庫 Database altered.
總結:
1、從上能夠說是涉及到各個場景控制文件的損壞恢復,相對是比較全面的,但生產環境下的恢復狀況要比咱們預想的複雜的多,應根據各類狀況,儘可能將損失下降到最小。
2、還有個在linux環境未關庫狀況下,形成控制文件誤刪,可經過/proc進程號恢復,這邊就不作介紹了。
3、最後得強調一下,有效的備份重於一切,對生產環境存敬畏之心,千萬不要存僥倖心理,墨菲定律就在咱們身邊。