rman恢復的基本知識

we6100發表於2014-04-06
1、口令檔案的恢復
口令檔案的路徑:$ORACLE_HOME/dbs目錄下
cd $ORACLE_HOME/dbs
rm orapworcl
orapwd file=orapworcl password=oracle entries=5; //重新建立一個檔案,entries的意思:DBA的使用者最多有5個

2、spfile丟失

SQL> startup nomount
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initorcl.ora'

rman下

RMAN> set dbid 2694191837
executing command: SET DBID

RMAN>  restore spfile from autobackup; //如果沒有成功,說明configure controlfile autobackup on 沒有配置,下次配置完成後,就可以恢復成功

Starting restore at 01-APR-14
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/01/2014 21:01:16
RMAN-12010: automatic channel allocation initialization failed
RMAN-06403: could not obtain a fully authorized session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory

指定路徑恢復
RMAN> set dbid 2694191837
executing command: SET DBID

RMAN> startup force nomount
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initjiagulun.ora'

starting Oracle instance without parameter file for retrival of spfile
Oracle instance started

Total System Global Area     159383552 bytes

Fixed Size                     2019224 bytes
Variable Size                 67108968 bytes
Database Buffers              83886080 bytes
Redo Buffers                   6369280 bytes

RMAN> restore spfile from '/home/oracle/rmanbak/inc0_0hp4lqu4_20140401'; //該路徑可以在以前備份日誌上找到

Starting restore at 01-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK

channel ORA_DISK_1: autobackup found: /home/oracle/rmanbak/inc0_0hp4lqu4_20140401
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 01-APR-14

3、controlfile 丟失:
SQL> SHOW PARAMETER CONTROL_FILES
//檢視備份檔案位置

SQL> startup nomount; //丟失control檔案可以到nomount階段
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  2020192 bytes
Variable Size             125832352 bytes
Database Buffers          150994944 bytes
Redo Buffers                6365184 bytes
SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying control file, check alert log for more info

SQL> shutdown immediate
ORA-01507: database not mounted

在RMAN下
RMAN> startup nomount;

Oracle instance started

Total System Global Area     285212672 bytes

Fixed Size                     2020192 bytes
Variable Size                125832352 bytes
Database Buffers             150994944 bytes
Redo Buffers                   6365184 bytes

RMAN> restore controlfile from autobackup;//因為沒有啟用autobackup,所以失敗

Starting restore at 01-APR-14
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 04/01/2014 21:43:22
RMAN-12010: automatic channel allocation initialization failed
RMAN-06403: could not obtain a fully authorized session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory


RMAN> restore controlfile from '/home/oracle/rmanbak/inc0_0gp4lqtt_20140401';

Starting restore at 01-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=157 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output filename=/u01/app/oracle/oradata/JIAGULUN/controlfile/o1_mf_9mojz9ot_.ctl
output filename=/u01/app/oracle/flash_recovery_area/ORCL/controlfile/o1_mf_9mojzb1m_.ctl
Finished restore at 01-APR-14
恢復成功。

但是在sql下,還是無法開啟
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open RESETLOGS;
alter database open RESETLOGS
*
ERROR at line 1:
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1:
'/u01/app/oracle/oradata/ORCL/datafile/o1_mf_system_7p5b14xs_.dbf'

出錯, redo log的scn記錄在controlfile裡面的,因為我們有新的controlfile,所以需要resetlogs;

RMAN下
RMAN> recover database; //以當前的控制檔案裡所記錄的SCN來恢復資料檔案的資料塊

Starting recover at 01-APR-14
Starting implicit crosscheck backup at 01-APR-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=155 devtype=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 01-APR-14

Starting implicit crosscheck copy at 01-APR-14
using channel ORA_DISK_1
using channel ORA_DISK_2
Finished implicit crosscheck copy at 01-APR-14

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1
using channel ORA_DISK_2

starting media recovery

archive log thread 1 sequence 102 is already on disk as file /u01/app/oracle/flash_recovery_area/JIAGULUN/onlinelog/o1_mf_2_7p5b34v6_.log
archive log thread 1 sequence 103 is already on disk as file /u01/app/oracle/flash_recovery_area/JIAGULUN/onlinelog/o1_mf_3_7p5b36x4_.log
archive log thread 1 sequence 104 is already on disk as file /u01/app/oracle/flash_recovery_area/JIAGULUN/onlinelog/o1_mf_1_7p5b31mg_.log
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/onlinelog/o1_mf_2_7p5b34v6_.log thread=1 sequence=102
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/onlinelog/o1_mf_3_7p5b36x4_.log thread=1 sequence=103
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/onlinelog/o1_mf_1_7p5b31mg_.log thread=1 sequence=104
media recovery complete, elapsed time: 00:00:02
Finished recover at 01-APR-14

成功開啟資料庫
SQL> alter database open RESETLOGS;//RESETLOGS會把online redelog file清空,資料檔案丟失.所以這個時候要做一個全備份。否則下次恢復會出錯

Database altered.

4、redo log 丟失

SQL>  select group# , member from v$logfile;//檢視redolog檔案位置

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.

Total System Global Area  285212672 bytes
Fixed Size                  2020192 bytes
Variable Size              88083616 bytes
Database Buffers          188743680 bytes
Redo Buffers                6365184 bytes
Database mounted.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/app/oracle/oradata/orcl/redo01.log'


SQL> recover database until cancel;
Media recovery complete.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs;//RESETLOGS會把online redelog file清空,資料檔案丟失.所以這個時候要做一個全備份。否則下次恢復會出錯

Database altered.

5、資料檔案恢復
SQL> select FILE#,  NAME,STATUS from v$datafile;  //檢視資料檔案位置狀態

RMAN> sql "alter database datafile 4 offline";//模擬丟失

using target database control file instead of recovery catalog
sql statement: alter database datafile 4 offline
恢復:
RMAN> restore datafile 4 ;

Starting restore at 01-APR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=141 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/inc0_0bp4m461_20140401
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rmanbak/inc0_0bp4m461_20140401 tag=LEVEL0
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
Finished restore at 01-APR-14

RMAN> recover datafile 4;

Starting recover at 01-APR-14
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:05
Finished recover at 01-APR-14

RMAN> sql "alter database datafile 4 online";
sql statement: alter database datafile 4 online

6、表空間丟失
SQL> select tablespace_name ,sum(bytes)/1024/1024 M from dba_data_files group by tablespace_name;//檢視錶空間及大小

RMAN> sql "alter tablespace users offline";//模擬丟失

using target database control file instead of recovery catalog
sql statement: alter tablespace users offline
恢復:
RMAN>  restore tablespace users;

Starting restore at 01-APR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=140 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/inc0_0bp4m461_20140401
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rmanbak/inc0_0bp4m461_20140401 tag=LEVEL0
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 01-APR-14

RMAN> recover tablespace users;

Starting recover at 01-APR-14
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 01-APR-14

RMAN> sql "alter tablespace users online";
sql statement: alter tablespace users online

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

相關文章