rman还原控制文件(四)

RMAN使用恢复目录还原控制文件
1.人为删除所有控制文件

[root@oracle11g test]# ls -lrt
total 2213868
-rw-r—– 1 oracle oinstall 20979712 Feb 1 11:37 temp01.dbf
-rw-r—– 1 oracle oinstall 11804672 Feb 1 22:31 users01.dbf
-rw-r—– 1 oracle oinstall 52436992 Feb 1 22:31 test01.dbf
-rw-r—– 1 oracle oinstall 52429312 Feb 1 22:31 redo03.log
-rw-r—– 1 oracle oinstall 52429312 Feb 1 22:31 redo02.log
-rw-r—– 1 oracle oinstall 104865792 Feb 1 22:31 example01.dbf
-rw-r—– 1 oracle oinstall 576724992 Feb 1 22:37 sysaux01.dbf
-rw-r—– 1 oracle oinstall 492838912 Feb 1 22:42 undotbs01.dbf
-rw-r—– 1 oracle oinstall 838868992 Feb 1 22:42 system01.dbf
-rw-r—– 1 oracle oinstall 52429312 Feb 1 22:42 redo01.log
-rw-r—– 1 oracle oinstall 9814016 Feb 1 22:42 control03.ctl
-rw-r—– 1 oracle oinstall 9814016 Feb 1 22:42 control02.ctl
-rw-r—– 1 oracle oinstall 9814016 Feb 1 22:42 control01.ctl
[root@oracle11g test]# rm -rf control*.ctl
[root@oracle11g test]# ls -lrt
total 2185068
-rw-r—– 1 oracle oinstall 20979712 Feb 1 11:37 temp01.dbf
-rw-r—– 1 oracle oinstall 11804672 Feb 1 22:31 users01.dbf
-rw-r—– 1 oracle oinstall 52436992 Feb 1 22:31 test01.dbf
-rw-r—– 1 oracle oinstall 52429312 Feb 1 22:31 redo03.log
-rw-r—– 1 oracle oinstall 52429312 Feb 1 22:31 redo02.log
-rw-r—– 1 oracle oinstall 104865792 Feb 1 22:31 example01.dbf
-rw-r—– 1 oracle oinstall 576724992 Feb 1 22:37 sysaux01.dbf
-rw-r—– 1 oracle oinstall 492838912 Feb 1 22:42 undotbs01.dbf
-rw-r—– 1 oracle oinstall 838868992 Feb 1 22:42 system01.dbf
-rw-r—– 1 oracle oinstall 52429312 Feb 1 22:42 redo01.log

2.人为将数据库异常终止

[root@oracle11g test]# ps -ef | grep smon
oracle    4135     1  0 22:30 ?        00:00:00 ora_smon_test
root      3179  3123  0 22:45 pts/3    00:00:00 grep smon
[root@oracle11g test]# kill -9 4135

3.将数据库启动到nomount状态

SQL> startup nomount
ORACLE instance started.

Total System Global Area  327155712 bytes
Fixed Size                  1273516 bytes
Variable Size             138412372 bytes
Database Buffers          184549376 bytes
Redo Buffers                2920448 bytes

4.还原控制文件

[oracle@oracle11g admin]$ rman target sys/zzh_2046@test catalog rman/rman@jy

Recovery Manager: Release 10.2.0.5.0 - Production on Sun Feb 1 23:04:03 2015

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

connected to target database: test (not mounted)
connected to recovery catalog database

RMAN> restore controlfile;

Starting restore at 01-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/10.2.0/db/dbs/c-2155613261-20150201-01
channel ORA_DISK_1: restored backup piece 1
piece handle=/u01/app/oracle/10.2.0/db/dbs/c-2155613261-20150201-01 tag=TAG20150201T213315
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
output filename=/u01/app/oracle/oradata/test/control01.ctl
output filename=/u01/app/oracle/oradata/test/control02.ctl
output filename=/u01/app/oracle/oradata/test/control03.ctl
Finished restore at 01-FEB-15

5.执行完全恢复

RMAN> sql 'alter database mount';

sql statement: alter database mount
released channel: ORA_DISK_1

RMAN> recover database;

Starting recover at 01-FEB-15
Starting implicit crosscheck backup at 01-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
Crosschecked 8 objects
Finished implicit crosscheck backup at 01-FEB-15

Starting implicit crosscheck copy at 01-FEB-15
using channel ORA_DISK_1
Crosschecked 6 objects
Finished implicit crosscheck copy at 01-FEB-15

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

using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 3 is already on disk as file /u01/app/oracle/oradata/test/redo03.log
archive log thread 1 sequence 4 is already on disk as file /u01/app/oracle/oradata/test/redo01.log
archive log filename=/u01/app/oracle/oradata/test/redo03.log thread=1 sequence=3
archive log filename=/u01/app/oracle/oradata/test/redo01.log thread=1 sequence=4
media recovery complete, elapsed time: 00:00:01
Finished recover at 01-FEB-15



RMAN> sql 'alter database open resetlogs';

sql statement: alter database open resetlogs
new incarnation of database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

将控制文件还原到新目录
有一种将控制文件还原到一个或多个新目录的方法是修改control_files参数,然后用没有任何参数的restore controlfile命令将控制文件还原到默认位置。例如,如果在有些控制文件目录所在的磁盘出现故障还原控制文件,可以修改control_files参数将出现故障的磁盘使用其它的磁盘来替代,然后执行restore controlfile命令来还原控制文件。

如果不修改control_files参数也可以使用restore controlfile to ‘filename’ [from autobackup]命令来将控制文件还原到你所指定的位置。
示例:
RESTORE CONTROLFILE TO ‘/tmp/my_controlfile’;

下面的命令将使用自动备份将控制文件还原到’/u01/app/oracle/‘目录下

RMAN> restore controlfile to '/u01/app/oracle/control_temp.ctl' from autobackup;

Starting restore at 02-FEB-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=148 devtype=DISK

recovery area destination: /u01/app/oracle/flash_recovery_area
database name (or database unique name) used for search: TEST
channel ORA_DISK_1: autobackup found in the recovery area
channel ORA_DISK_1: autobackup found: /u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_02_02/o1_mf_s_870567448_bdwndtqk_.bkp
channel ORA_DISK_1: control file restore from autobackup complete
Finished restore at 02-FEB-15

上面的命令可以在数据库为nomount,mount,open状态下进行,因为不会覆盖任何当前使用的控制文件。在将控制文件还原到新目录后,可以修改control_files参数来引用新目录下的控制文件。

使用备份控制文件的限制
在使用备份控制文件还原数据库后,你必须执行recover database来恢复数据库并且必须执行alter database open resetlogs来打开数据库。

发表评论

电子邮件地址不会被公开。