在rman用语中,ldquo;还原rdquo;与ldquo;恢复rdquo;具有不同的含义,还原(restore)是指访问先前生成的备份集,从中得到一个或
在rman用语中,“还原”与“恢复”具有不同的含义,还原(restore)是指访问先前生成的备份集,从中得到一个或多个对象,然后再磁盘上的某个位置还原这些对象。还原与恢复时分离的。恢复(recovery)是一个使数据库与给定时间点相一致以保证能够打开这个数据库的实际操作。
如果丢失了所有的参数文件(spfile和pfile),而且开启了控制文件自动备份(rman> configure controlfile autobackup on;),我们可以从自动备份的控制文件+参数文件的备份集中恢复服务器的参数文件。不同的操作系统,自动备份的参数文件+控制文件保存的位置略有区别:
windows:$oracle_home%\database
linux/unix:$oracle_home/dbs
如果之前有自动备份控制文件+参数文件备份集,那么我们只需要简单执行一条语句:restore spfile from autobackup; 语句就可以恢复参数文件。执行该语句时,oracle会在默认位置中(或则在allocate channel命令定义的位置中)查找所需备份集,该备份集使用oracle默认的命名规则(%f),该命名规则在fra里面不适用(fra有自己的命名规则)。
示例:模拟参数文件丢失(先在脱机状态执行数据库全备,然后移出所有$oracle_home/dbs下的spfile和pfile文件到临时目录下)
数据库会启动失败:
sql> startup
ora-01078: failure in processing system parameters
lrm-00109: could not open parameter file '/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora'
方法一,使用默认配置进行参数文件恢复
启动rman进行参数文件的恢复:
[oracle@localhost ~] $ set oracle_sid=orcl
[oracle@localhost ~] $ rman target /
rman>set dbid = 1405321682
rman>startup nomount
rman>restore spfile from autobackup;
starting restore at 2015-06-06 21:24:27
allocated channel: ora_disk_1
channel ora_disk_1: sid=130 device type=disk
channel ora_disk_1: looking for autobackup on day: 20150606
channel ora_disk_1: looking for autobackup on day: 20150605
channel ora_disk_1: looking for autobackup on day: 20150604
channel ora_disk_1: looking for autobackup on day: 20150603
channel ora_disk_1: looking for autobackup on day: 20150602
channel ora_disk_1: looking for autobackup on day: 20150601
channel ora_disk_1: looking for autobackup on day: 20150531
channel ora_disk_1: no autobackup in 7 days found
rman-00571: ===========================================================
rman-00569: =============== error message stack follows ===============
rman-00571: ===========================================================
rman-03002: failure of restore command at 06/06/2015 21:24:29
rman-06172: no autobackup found or specified handle is not a valid copy or piece
错误分析
恢复报错,提示未找到有效的备份集。分析原因:正常来说,刚才做的数据库全备,并设置了configure autobackup on,应该是有参数文件备份的,但是为什么找不到了?默认配置恢复参数文件,oracle会到$oracle_home/dbs下寻找指定名称的备份集,从报错信息来看,默认情况下它会在该目录下寻找过去7天内创建的控制文件备份集(可以加上maxseq和maxdays来改变默认天数),如果没找到就报错。去$oracle_home/dbs目录下查看,确实没有任何备份集,从刚才的备份过程来看,oracle将控制文件自动保存到fra里面去了,而且使用的是fra里面的默认命令规则:
starting control file and spfile autobackup at 2015-06-06 21:22:36
piece handle=/home/oracle/app/flash_recovery_area/orcl/autobackup/2015_06_06/o1_mf_s_881702383_bq5x0wq0_.bkp comment=none
finished control file and spfile autobackup at 2015-06-06 21:22:37
released channel: c1
由于数据库是启动在nomount状态,参数文件丢失,因此并没有加载参数文件,oracle也就无法定位fra,因此oracle不会去fra中寻找(测试过将c-1405321682-20150606-01放在fra中,仍然无法恢复),而是去$oracle_home/dbs下寻找(补充说明2)。手工恢复参数文件,查看rman的默认配置,是否有设置控制文件的默认存储位置(注意了,nomount状态下只能看到rman最原始的配置信息,见下面的补充说明1,看不到修改的配置信息,必须将数据库启动到mount状态):
rman> show all;
rman configuration parameters for database with db_unique_name orcl are:
configure retention policy to redundancy 1; # default
configure backup optimization off; # default
configure default device type to disk;
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '%f'; # default
configure device type disk parallelism 1 backup type to backupset; # default
。。。。
错误解决
备份目录确实是使用的是默认的,为什么自动备份控制文件和参数文件的时候会将备份集保存到fra中去?确实很奇怪,手工设置一下备份路径:
rman> configure controlfile autobackup format for device type disk to '%f';
rman> show all;
rman configuration parameters for database with db_unique_name orcl are:
configure retention policy to redundancy 1; # default
configure backup optimization off; # default
configure default device type to disk;
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '%f';
configure device type disk parallelism 1 backup type to backupset; # default
。。。。。
发现 configure controlfile autobackup format for device type disk to '%f'; 后面的default没有的,但是值还是不变,在执行一次备份:
rman> run
