RMAN备份与恢复 —— 参数文件还原

在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

     2> {
     3> allocate channel c1 device type disk;
     4> backup tablespace system format '/storage/database/oracle/backupset/online/backup_%U.bkp';
     5> backup current controlfile;
     6> RELEASE CHANNEL c1;
     7> }
     。。。。。。
     Starting Control File and SPFILE Autobackup at 2015-06-07 10:24:00
     piece handle=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/c-1405321682-20150607-01 comment=NONE
     Finished Control File and SPFILE Autobackup at 2015-06-07 10:24:01

     released channel: c1

     哈哈,参数文件和控制文件的备份集保存到正确的默认路径下面了。其实这个操作什么也没改,但重新设置一下就好了,这应该是Oracle的bug。再次模拟参数文件的丢失,执行参数文件的恢复:
     RMAN> restore spfile from autobackup;

     Starting restore at 2015-06-07 13:33:27
     using channel ORA_DISK_1

     channel ORA_DISK_1: AUTOBACKUP found: c-1405321682-20150607-01
     channel ORA_DISK_1: restoring spfile from AUTOBACKUP c-1405321682-20150607-01
     channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
     Finished restore at 2015-06-07 13:33:28

     
     RMAN> shutdown immediate

     Oracle instance shut down
     RMAN> startup

 
方法二,使用指定备份集的方式进行恢复
     [oracle@localhost ~] $ set oracle_sid=orcl
     [oracle@localhost ~] $ rman target /
     RMAN>set DBID = 1405321682
     RMAN>startup nomount
     RMAN>restore spfile from '/home/oracle/app/flash_recovery_area/ORCL/autobackup/2015_06_06/o1_mf_s_881702383_bq5x0wq0_.bkp';
     RMAN>shutdown immediate
 
方法三,使用临时参数文件进行恢复
     如果忘记了待恢复数据库的DBID,上面的两种方式就失效了,可以使用临时参数文件来恢复spfile,前提是正确配置临时参数文件。因为临时参数文件可以指定FRA的位置,那么Oracle执行restore  spfile from autobackup的时候就会去FRA中寻找。(没有实践)
     [oracle@localhost ~] $ set oracle_sid=orcl
     [oracle@localhost ~] $ rman target /
     RMAN>startup nomount;     --加载临时参数文件
     RMAN>restore spfile from autobackup;
     RMAN>shutdown immediate
 
补充:
1,在nomount状态下看到的默认配置信息:
RMAN> show all;

RMAN configuration parameters for database with db_unique_name DUMMY are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
 
2,为什么Oracle会到$ORACLE_HOME/dbs下寻找控制文件备份集?
you're using Flash recovery area and Oracle managed files for backup without RMAN catalog. When you start your instance with STARTUP FORCE NOMOUNT, Oracle set instance with minimal parameters and doesn't have a clue about where your flash recovery area is located. Oracle is looking for autobackup in "well" known locations (dbs on Unix, database on Windows) for a file that conforms to notation: c-IIIIIIIIII-YYYYMMDD-QQ (this is set with %F parameter). In your case Oracle doesn't find one because it's not there. 

--------------------------------------推荐阅读 --------------------------------------

--------------------------------------分割线 --------------------------------------

相关推荐