【RMAN】SYSTEM表空間資料檔案丟失恢復模擬

secooler發表於2010-07-15
只要存在有效的RMAN備份,恢復SYSTEM表空間資料檔案丟失故障是比較容易的。
注意,這裡強調的是存在有效可用的備份介質。曾經遇到一個非常無奈的場景:catalog資料庫與備份的目標庫放在了同一個資料庫中,此時當SYSTEM表空間發生不測之後,因為catalog資料庫與目標資料庫同時發生問題,導致恢復變得艱難。敬告:制定備份策略的時候一定要考慮周全。

這裡演示的是最常見的使用RMAN恢復SYSTEM表空間丟失的資料方法。

1.連線到catalog資料庫完成對資料庫的備份
[oracle@secdb oradata]$ rman target / catalog rman_catalog/rman_catalog@catalog

Recovery Manager: Release 10.2.0.1.0 - Production on Thu Jul 15 22:14:24 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: ORA10G (DBID=4067316777)
connected to recovery catalog database

RMAN> run{
backup full database
format '/u01/app/oracle/rmanbak/full_bk1_%u%p%s.rmn'
include current controlfile;
backup archivelog all
format '/u01/app/oracle/rmanbak/arch_bk1_%u%p%s.rmn'
delete all input;
}

…… 省略輸出結果 ……

2.模擬SYSTEM表空間資料檔案丟失
sys@ora10g> col name for a60
sys@ora10g> select file#,name from v$datafile;

     FILE# NAME
---------- ----------------------------------------------------------
         1 /u01/app/oracle/oradata/ora10g/system01.dbf
         2 /u01/app/oracle/oradata/ora10g/undotbs01.dbf
         3 /u01/app/oracle/oradata/ora10g/sysaux01.dbf
         4 /u01/app/oracle/oradata/ora10g/users01.dbf
         5 /u01/app/oracle/oradata/ora10g/example01.dbf
         6 /u01/app/oracle/oradata/ora10g/user_08.dbf

sys@ora10g> ! rm -f /u01/app/oracle/oradata/ora10g/system01.dbf

故障現象舉例:
sys@ora10g> select * from cat;
select * from cat
              *
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-01116: error in opening database file 1
ORA-01110: data file 1: '/u01/app/oracle/oradata/ora10g/system01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3

sys@ora10g> shutdown immediate;
ORA-01116: error in opening database file 1
ORA-01110: data file 1: '/u01/app/oracle/oradata/ora10g/system01.dbf'
ORA-27041: unable to open file
Linux Error: 2: No such file or directory
Additional information: 3

sys@ora10g> shutdown abort;
ORACLE instance shut down.

NotConnected@> startup;
ORACLE instance started.

Total System Global Area  314572800 bytes
Fixed Size                  1219136 bytes
Variable Size             125830592 bytes
Database Buffers          180355072 bytes
Redo Buffers                7168000 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u01/app/oracle/oradata/ora10g/system01.dbf'

NotConnected@> select status from v$instance;

STATUS
------------
MOUNTED

3.使用RMAN完成資料檔案恢復
1)連線到catalog資料庫
[oracle@secdb oradata]$ rman target / catalog rman_catalog/rman_catalog@catalog

Recovery Manager: Release 10.2.0.1.0 - Production on Thu Jul 15 22:16:51 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: ORA10G (DBID=4067316777, not open)
connected to recovery catalog database

2)還原1號資料檔案,此檔案即為SYSTEM表空間丟失的資料檔案
RMAN> restore datafile 1;

Starting restore at 15-JUL-10
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/ora10g/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/rmanbak/full_bk1_0flis4k9115.rmn
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/rmanbak/full_bk1_0flis4k9115.rmn tag=TAG20100715T171449
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
Finished restore at 15-JUL-10

3)對1號資料檔案進行恢復
RMAN> recover datafile 1;

Starting recover at 15-JUL-10
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:03

Finished recover at 15-JUL-10

4)將資料庫啟動到OPEN狀態
RMAN> alter database open;

database opened

5)驗證資料庫的可用性
[oracle@secdb oradata]$ sqlplus  / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jul 15 22:24:14 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

sys@ora10g> select status from v$instance;

STATUS
------------
OPEN

4.小結
恢復丟失的資料檔案的過程是非常簡便的。真正要重視的備份策略的科學性和備份介質的有效性,前者需要需要對備份策略做深入的策劃,後者可以透過定期的備份介質有效性驗證來保證。

Good luck.

secooler
10.07.15

-- The End --

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-668139/,如需轉載,請註明出處,否則將追究法律責任。

相關文章