【Oracle】rman 恢复只读表空间数据库

在默认情况下,即使丢失了只读的数据文件,RMAN也不会在执行完全数据库还原操作时还原只读的数据文件。
要在完全恢复期间还原只读的数据文件,就必须在restore命令中使用check readonly参数:

静态或历史数据保存在只读表空间中是一个很好的做法,特别是对于数据仓库类型的环境。
使用RMAN SKIP READONLY命令,我们可以通过从数据库备份集中排除这些只读表空间来减少备份窗口和开销。
但是,我们需要记住,我们需要至少在备份表空间后才能读取,之后我们可以使用SKIP READONLY命令从每日或每周的数据库备份中排除这些表空间。
然而,在进行恢复时,我们需要使用CHECK READONLY关键字,否则默认情况下,只读表空间将不会恢复,因此恢复也将绕过这些表空间。随后尝试打开数据库将失败。

案列:
RMAN> restore database;
Starting restore at 12-AUG-09 using channel ORA_SBT_TAPE_1 using channel ORA_DISK_1 datafile 4 not processed because file is read-only datafile 6 not processed because file is read-only datafile 9 not processed because file is read-only channel ORA_SBT_TAPE_1: starting datafile backupset restore channel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup set restoring datafile 00001 to /u02/oradata/testdb/system01.dbf restoring datafile 00002 to /u02/oradata/testdb/undotbs01.dbf restoring datafile 00003 to /u02/oradata/testdb/sysaux01.dbf restoring datafile 00005 to /u02/oradata/testdb/example01.dbf channel ORA_SBT_TAPE_1: reading from backup piece 08kmb8f7_1_1 channel ORA_SBT_TAPE_1: restored backup piece 1 piece handle=08kmb8f7_1_1 tag=TAG20090810T120039 channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:10:36 Finished restore at 12-AUG-09
RMAN> recover database; Starting recover at 12-AUG-09
using channel ORA_SBT_TAPE_1
using channel ORA_DISK_1
datafile 4 not processed because file is read-only
datafile 6 not processed because file is read-only
datafile 9 not processed because file is read-only
channel ORA_SBT_TAPE_1: starting incremental datafile backupset restore
channel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u02/oradata/testdb/system01.dbf
.....
.......

archive log filename=/u02/oradata/testdb/arch/arch.36.1.694170424.log thread=1 sequence=36
archive log filename=/u02/oradata/testdb/arch/arch.37.1.694170424.log thread=1 sequence=37
archive log filename=/u02/oradata/testdb/arch/arch.38.1.694170424.log thread=1 sequence=38
media recovery complete, elapsed time: 00:00:43
Finished recover at 12-AUG-09

RMAN> alter database open;

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 08/12/2009 12:55:30
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u02/oradata/testdb/users03.dbf'

现在,只读表格也被还原,但是我们注意到恢复阶段将跳过这些表空间,因为不需要恢复,因为这些表空间在上述这些表空间被替换为只读后才进行上次备份,因此没有发生任何更改。
MAN> restore database check readonly; Starting restore at 12-AUG-09
using channel ORA_SBT_TAPE_1
using channel ORA_DISK_1

channel ORA_SBT_TAPE_1: starting datafile backupset restore
channel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u02/oradata/testdb/system01.dbf
restoring datafile 00002 to /u02/oradata/testdb/undotbs01.dbf
restoring datafile 00003 to /u02/oradata/testdb/sysaux01.dbf restoring datafile 00004 to /u02/oradata/testdb/users03.dbf restoring datafile 00005 to /u02/oradata/testdb/example01.dbf restoring datafile 00006 to /u02/oradata/testdb/users02.dbf
restoring datafile 00009 to /u02/oradata/testdb/users01.dbf channel ORA_SBT_TAPE_1: reading from backup piece 08kmb8f7_1_1
channel ORA_SBT_TAPE_1: restored backup piece 1
piece handle=08kmb8f7_1_1 tag=TAG20090810T120039
channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:05:25
Finished restore at 12-AUG-09



RMAN> recover database; Starting recover at 12-AUG-09
using channel ORA_SBT_TAPE_1
using channel ORA_DISK_1
datafile 4 not processed because file is read-only
datafile 6 not processed because file is read-only
datafile 9 not processed because file is read-only
channel ORA_SBT_TAPE_1: starting incremental datafile backupset restore
channel ORA_SBT_TAPE_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u02/oradata/testdb/system01.dbf
destination for restore of datafile 00002: /u02/oradata/testdb/undotbs01.dbf
destination for restore of datafile 00003: /u02/oradata/testdb/sysaux01.dbf
destination for restore of datafile 00005: /u02/oradata/testdb/example01.dbf
channel ORA_SBT_TAPE_1: reading from backup piece 0akmb8uu_1_1
channel ORA_SBT_TAPE_1: restored backup piece 1
piece handle=0akmb8uu_1_1 tag=TAG20090810T120901
channel ORA_SBT_TAPE_1: restore complete, elapsed time: 00:00:07

starting media recovery

archive log thread 1 sequence 36 is already on disk as file /u02/oradata/testdb/arch/arch.36.1.694170424.log
archive log thread 1 sequence 37 is already on disk as file /u02/oradata/testdb/arch/arch.37.1.694170424.log
archive log thread 1 sequence 38 is already on disk as file /u02/oradata/testdb/arch/arch.38.1.694170424.log
archive log thread 1 sequence 39 is already on disk as file /u02/oradata/testdb/arch/arch.39.1.694170424.log
archive log thread 1 sequence 40 is already on disk as file /u02/oradata/testdb/arch/arch.40.1.694170424.log
archive log filename=/u02/oradata/testdb/arch/arch.36.1.694170424.log thread=1 sequence=36
archive log filename=/u02/oradata/testdb/arch/arch.37.1.694170424.log thread=1 sequence=37
archive log filename=/u02/oradata/testdb/arch/arch.38.1.694170424.log thread=1 sequence=38
media recovery complete, elapsed time: 00:00:39
Finished recover at 12-AUG-09

RMAN> alter database open;

database opened
请使用浏览器的分享功能分享到微信等