首页 > 代码库 > Control File and Server Parameter File Autobackup Options实验详细解析
Control File and Server Parameter File Autobackup Options实验详细解析
转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/42192273
Control File andServer Parameter File Autobackup Options解析
When restoring an autobackup, thecommands and options that you use depend on the autobackup type (control fileor server parameter file) and location (inside or outside fast recovery area).The options are summarized in Table 3-10.
Table 3-10 RESTORE ... FROMAUTOBACKUP
Restore Object | Autobackup Location | Run SET DBID? | Specify RECOVERY AREA on RESTORE? | Specify DB_NAME or DB_UNIQUE_NAME on RESTORE? | Run SET CONTROLFILE AUTOBACKUP FORMAT? |
SPFILE | Recovery area | No | Yes | Yes | No |
SPFILE | Outside recovery area | Yes | No | No | Only if autobackup is not in default location |
Control file | Recovery area | No | Only if autobackup is in noncurrent recovery area | Only if autobackup is in noncurrent recovery area and uses a noncurrent DB_UNIQUE_NAME | No |
Control file | Outside recovery area | Yes | No | No | Only if autobackup is not in default location |
根据以上SG给出的官方文档,我们一起来分析并做实验:
第一种情况:用autobackup自动还原spfile的条件是:
1、备份的spfile在闪回区(db_recovery_file_dest)
2、在还原spfile时(restore spfile)无需设DBID
3、在还原spfile时要指定闪回区和数据库名或数据库唯一名(resore spfile from autobackup 后面要指定闪回区和DB_NAME OR DB_UNIQUE_NAME)
4、不需要在RMAN中配置控件文件自动备份的位置格式,默认即可
实验过程对应的上面四个步骤:
1、检查闪回区有没有设置
SQL> show parameter db_recover NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_recovery_file_dest string /u01/app/oracle/flash db_recovery_file_dest_size big integer 2G
以上已设好闪回区,如果没有设置用以下命令
alter system setdb_recovery_file_dest_size=2G;
alter system setdb_recovery_file_dest=‘/u01/app/oracle/flash‘;
在备份时要确定让参数文件自动备份到闪回区,必须满足两个条件如下:
CONFIGURECONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘%F‘; # default
注:如果不是default,请用从下命令
CONFIGURECONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK CLEAR;
把CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPEDISK TO ‘%F‘;设为
CONFIGURECONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘%F‘; # default
正确的如下:
下面,我们来做个备份,我对5号文件做备份,自动备份出controlfile and SPFILE到闪回区
2、接下来我们对SPFILE做还原restotre,看不会不会要求设置DBID
先用手工编辑的pfile把数据库启动到nomount状态,即启动实例
[root@jfdb tmp]# vi /tmp/pfile.ora *.CONTROL_FILES=‘/u01/app/oracle/oradata/jfocp/control01.ctl‘,‘/u01/app/oracle/oradata/jfocp/control02.ctl‘ *.DB_NAME=‘jfocp‘ *.db_recovery_file_dest=‘/u01/app/oracle/flash‘ *.db_recovery_file_dest_size=2G RMAN> shutdown abort; Oracle instance shut down RMAN> startup nomount pfile=‘/tmp/pfile.ora‘; connected to target database (not started) Oracle instance started Total System Global Area 250560512 bytes Fixed Size 2227256 bytes Variable Size 192938952 bytes Database Buffers 50331648 bytes Redo Buffers 5062656 bytes
33、在还原spfile时要指定闪回区和数据库名或数据库唯一名,在restore没提示设置DBID
RMAN> restore spfile from autobackup DB_NAME=JFOCP RECOVERY AREA=‘/u01/app/oracle/flash/‘; Starting restore at 26-DEC-14 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=171 device type=DISK recovery area destination: /u01/app/oracle/flash/ database name (or database unique name) used for search: JFOCP channel ORA_DISK_1: AUTOBACKUP /u01/app/oracle/flash/JFOCP/autobackup/2014_12_26/o1_mf_s_867332906_b9sxobng_.bkp found in the recovery area channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141226 channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/flash/JFOCP/autobackup/2014_12_26/o1_mf_s_867332906_b9sxobng_.bkp channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 26-DEC-14
如果不定指闪回区,默认是去$ORACLE_HOME/dbs找c-dbid-sysdate-sequence格式的备份,大家看到这个报错,明白了吧
RMAN> restore spfile from autobackup; Starting restore at 26-DEC-14 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=171 device type=DISK channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141226 channel ORA_DISK_1: AUTOBACKUP found: c-1966040361-20141226-06 channel ORA_DISK_1: restoring spfile from AUTOBACKUP c-1966040361-20141226-06 channel ORA_DISK_1: the AUTOBACKUP does not contain an SPFILE channel ORA_DISK_1: trying older AUTOBACKUP... channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141226 channel ORA_DISK_1: AUTOBACKUP found: c-1966040361-20141226-05 channel ORA_DISK_1: restoring spfile from AUTOBACKUP c-1966040361-20141226-05 channel ORA_DISK_1: the AUTOBACKUP does not contain an SPFILE channel ORA_DISK_1: trying older AUTOBACKUP... channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141226 channel ORA_DISK_1: AUTOBACKUP found: c-1966040361-20141226-04 channel ORA_DISK_1: restoring spfile from AUTOBACKUP c-1966040361-20141226-04 channel ORA_DISK_1: the AUTOBACKUP does not contain an SPFILE channel ORA_DISK_1: trying older AUTOBACKUP... channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141226 channel ORA_DISK_1: AUTOBACKUP found: c-1966040361-20141226-03 channel ORA_DISK_1: restoring spfile from AUTOBACKUP c-1966040361-20141226-03 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of restore command at 12/26/2014 13:53:04 ORA-19687: SPFILE not found in backup set
4、再次确定要把这个实验做成功,必须是:
CONFIGURE CONTROLFILE AUTOBACKUPFORMAT FOR DEVICE TYPE DISK TO ‘%F‘; # default
第二种情况:用autobackup自动还原spfile的条件是:
1、备份的spfile不在闪回区(db_recovery_file_dest)
2、在还原spfile时(restore spfile)需要设DBID #这里没要求设置DBID
3、在还原spfile时要不需要指定闪回区和数据库名或数据库唯一名(resore spfile from autobackup 后面要指定闪回区和DB_NAME OR DB_UNIQUE_NAME)
4、RMAN中配置控件文件自动备份的位置,即不是默认的位置
实验过程对应的上面四个步骤:
1、自动备份的参数文件不在闪回区,要使自动备份的参数不在闪回区只要满足于第4个条件即:RMAN中配置控件文件自动备份的位置,即不是默认的位置,也就是这条命令RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/backup/%F‘; new RMAN configuration parameters: CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/backup/%F‘; new RMAN configuration parameters are successfully stored
2、我们来做个自动备份
(1)我们把RMAN中控件文件自动备份的位置设在一个非默认位置,即CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FORDEVICE TYPE DISK TO ‘/backup/%F‘;
默认位置是($ORACLE_HOME/dbs)
RMAN> show all; RMAN configuration parameters for database with db_unique_name JFOCP are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/backup/%F‘; 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 CHANNEL DEVICE TYPE DISK FORMAT ‘‘; 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 CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/u01/app/oracle/product/11.2.0/dbs/snapcf_jfocp.f‘; # default
(2)我们对5号文件做个备份,会自动备份出控制件文件和参数文件,而且放在了非默认的位置,并没有放到闪回区。
RMAN> backup datafile 5; Starting backup at 27-DEC-14 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=178 device type=DISK channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00005 name=/u01/app/oracle/oradata/jfocp/tp101.dbf channel ORA_DISK_1: starting piece 1 at 27-DEC-14 channel ORA_DISK_1: finished piece 1 at 27-DEC-14 piece handle=/u01/app/oracle/product/11.2.0/dbs/35pr7bbt_1_1 tag=TAG20141227T120933 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 Finished backup at 27-DEC-14 Starting Control File and SPFILE Autobackup at 27-DEC-14 piece handle=/backup/c-1966040361-20141227-03 comment=NONE Finished Control File and SPFILE Autobackup at 27-DEC-14
3、在还原spfile时要无须指定闪回区和数据库名或数据库唯一名
(1)删除参数
rm-/u01/app/oracle/product/11.2.0/dbs/spfile*
rm -/u01/app/oracle/product/11.2.0/dbs/init*
(2)关闭库
RMAN> shutdown abort;
Oracle instance shut down
(3)利用RMAN内部配置的参数启动实例
RMAN> startup nomount; connected to target database (not started) startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file ‘/u01/app/oracle/product/11.2.0/dbs/initjfocp.ora‘ starting Oracle instance without parameter file for retrieval of spfile Oracle instance started Total System Global Area 158662656 bytes Fixed Size 2226456 bytes Variable Size 104859368 bytes Database Buffers 46137344 bytes Redo Buffers 5439488 bytes
(4)自动还原pfile
RMAN> restore spfile from autobackup; RMAN> restore spfile from autobackup; Starting restore at 27-DEC-14 using channel ORA_DISK_1 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141227 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141226 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141225 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141224 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141223 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141222 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141221 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 12/27/2014 12:13:21 RMAN-06172: no AUTOBACKUP found or specified handle is not a valid copy or piece
说明没找到自动备份的参数文件,原因是根据RMAN默认的参数来找到的,即
CONFIGURE CONTROLFILEAUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘%F‘; # default(在没有配置闪回的情况下默认一般是去$ORACLE_HOME/dbs下去找自动备份)
设置参数指定自动备份的目录,指向/backup/
RMAN> set controlfile autobackup formatfor device type disk to ‘/backup/%F‘;
executing command: SETCONTROLFILE AUTOBACKUP FORMAT
再次利用自动备份的参数文件还原参数,成功!此时没要求提供DBID
RMAN> restore spfile from autobackup; Starting restore at 27-DEC-14 using channel ORA_DISK_1 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20141227 channel ORA_DISK_1: AUTOBACKUP found: /backup/c-1966040361-20141227-03 channel ORA_DISK_1: restoring spfile from AUTOBACKUP /backup/c-1966040361-20141227-03 channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 27-DEC-14
第三种情况,自动还原控制文件,我就不详细说明了,直接看实验步骤。
1、确定设置闪回区
SQL> show parameter recover
NAME TYPE VALUE
------------------------------------ -----------------------------------------
db_recovery_file_dest string
db_recovery_file_dest_size big integer 0
db_unrecoverable_scn_tracking boolean TRUE
recovery_parallelism integer 0
SQL> alter system setdb_recovery_file_dest_size=2G;
System altered.
SQL> alter system set db_recovery_file_dest=‘/u01/app/oracle/flash‘;
System altered.
2、确认CONTROLFILE AUTOBACKUP FORMAT是默认设置
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMATFOR DEVICE TYPE DISK clear;
old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICETYPE DISK TO ‘/backup/%F‘;
RMAN configuration parameters aresuccessfully reset to default value
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILEAUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘%F‘; # default
3、备份5号文件,会自动备份出控制文件和参数文件,并会备份到闪回区
RMAN> backup datafile 5;
Starting backup at 27-DEC-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) inbackup set
input datafile file number=00005name=/u01/app/oracle/oradata/jfocp/tp101.dbf
channel ORA_DISK_1: starting piece 1 at 27-DEC-14
channel ORA_DISK_1: finished piece 1 at 27-DEC-14
piecehandle=/u01/app/oracle/flash/JFOCP/backupset/2014_12_27/o1_mf_nnndf_TAG20141227T123240_b9wfm95z_.bkptag=TAG20141227T123240 comment=NONE
channel ORA_DISK_1: backup set complete, elapsedtime: 00:00:03
Finished backup at 27-DEC-14
Starting Control File and SPFILE Autobackup at27-DEC-14
piece handle=/u01/app/oracle/flash/JFOCP/autobackup/2014_12_27/o1_mf_s_867414763_b9wfmd9s_.bkpcomment=NONE
Finished Control File and SPFILEAutobackup at 27-DEC-14
4、自动还原控制文件,不需要提供DBID,而且还原命令中也需要指定闪回区和数据库名称(因为我们自动备份的控制文件和参数文件在闪回区)
(1)关闭库
RMAN> shutdown abort;
Oracle instance shut down
(2)删除控制文件
[oracle@jfdb jfocp]$ rm -rfcontrol*
(3)启动实例
RMAN> startup nomount;
connected to target database (not started)
Oracle instance started
Total System Global Area 250560512 bytes
Fixed Size 2227256 bytes
Variable Size 192938952 bytes
Database Buffers 50331648 bytes
Redo Buffers 5062656 bytes
(4)用autobackup还原控制文件,这里并没有提示设置DBID
RMAN> restore controlfile from autobackup;
Starting restore at 27-DEC-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=171 device type=DISK
recovery area destination: /u01/app/oracle/flash
database name (or database unique name) used forsearch: JFOCP
channel ORA_DISK_1: AUTOBACKUP/u01/app/oracle/flash/JFOCP/autobackup/2014_12_27/o1_mf_s_867414763_b9wfmd9s_.bkpfound in the recovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day:20141227
channel ORA_DISK_1: restoring control file fromAUTOBACKUP/u01/app/oracle/flash/JFOCP/autobackup/2014_12_27/o1_mf_s_867414763_b9wfmd9s_.bkp
channel ORA_DISK_1: control file restore fromAUTOBACKUP complete
output filename=/u01/app/oracle/oradata/jfocp/control01.ctl
output filename=/u01/app/oracle/oradata/jfocp/control02.ctl
Finished restore at 27-DEC-14
5、启动库到MOUNT
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
6、恢复数据库
RMAN> recover database;
Starting recover at 27-DEC-14
Starting implicit crosscheck backup at 27-DEC-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=172 device type=DISK
Crosschecked 64 objects
Finished implicit crosscheck backup at 27-DEC-14
Starting implicit crosscheck copy at 27-DEC-14
using channel ORA_DISK_1
Finished implicit crosscheck copy at 27-DEC-14
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name:/u01/app/oracle/flash/JFOCP/autobackup/2014_12_27/o1_mf_s_867414763_b9wfmd9s_.bkp
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 7 isalready on disk as file /u01/app/oracle/oradata/jfocp/redo01.log
archived log filename=/u01/app/oracle/oradata/jfocp/redo01.log thread=1 sequence=7
media recovery complete, elapsed time: 00:00:00
Finishedrecover at 27-DEC-14
7、Resetlogs打开库
RMAN> alter database open resetlogs;
database opened
第四种情况,根据SG,我们直接看实验步骤
1、把CONFIGURE CONTROLFILE AUTOBACKUP FORMAT设为非默认位置
RMAN> CONFIGURECONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/backup/%F‘;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICETYPE DISK TO ‘/backup/%F‘;
new RMAN configuration parametersare successfully stored
2、根据以上设置,只要设为非默认位置,自动备份出的控制文件和参数文件就不会存放在闪回区,我们以备份5号文个做测试
(1)确定RMAN自动备份的配置
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMATFOR DEVICE TYPE DISK TO ‘/backup/%F‘;
(2)备份5号文件自动会备份控制文件和参数文件,并备份到指定目录
RMAN> backup datafile 5;
Starting backup at 27-DEC-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=162 device type=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) inbackup set
input datafile file number=00005name=/u01/app/oracle/oradata/jfocp/tp101.dbf
channel ORA_DISK_1: starting piece 1 at 27-DEC-14
channel ORA_DISK_1: finished piece 1 at 27-DEC-14
piece handle=/u01/app/oracle/flash/JFOCP/backupset/2014_12_27/o1_mf_nnndf_TAG20141227T124513_b9wgbs8d_.bkptag=TAG20141227T124513 comment=NONE
channel ORA_DISK_1: backup set complete, elapsedtime: 00:00:01
Finished backup at 27-DEC-14
Starting Control File and SPFILE Autobackup at27-DEC-14
piece handle=/backup/c-1966040361-20141227-07comment=NONE
Finished Control File and SPFILEAutobackup at 27-DEC-14
(3)删除全部控制文件
[oracle@jfdb jfocp]$ rm -rfcontrol*
(4)开始恢复
A.关闭库
RMAN> shutdown abort;
Oracle instance shut down
B.启动到NOMOUNT
RMAN> startup nomount;
connected to target database (not started)
Oracle instance started
Total System Global Area 250560512 bytes
Fixed Size 2227256 bytes
Variable Size 192938952 bytes
Database Buffers 50331648 bytes
Redo Buffers 5062656 bytes
C.查看RMAN配置
RMAN> show all;
RMAN configuration parameters for database withdb_unique_name JFOCP 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 DEVICETYPE DISK TO ‘%F‘; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUPTYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPEDISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPEDISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM ‘AES128‘; # default
CONFIGURE COMPRESSION ALGORITHM ‘BASIC‘ AS OFRELEASE ‘DEFAULT‘ OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; #default
D.修改自动备份位置指向/backup/
RMAN> SET CONTROLFILE AUTOBACKUP FORMAT FORDEVICE TYPE DISK TO ‘/backup/%F‘;
executing command: SETCONTROLFILE AUTOBACKUP FORMAT
E. 还原控件文件,也没有提示要设置DBID
RMAN>restore controlfile from autobackup;
Starting restore at 27-DEC-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=171 device type=DISK
recovery area destination: /u01/app/oracle/flash
database name (or database unique name) used forsearch: JFOCP
channel ORA_DISK_1: no AUTOBACKUPS found in therecovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day:20141227
channel ORA_DISK_1: AUTOBACKUP found:/backup/c-1966040361-20141227-07
channel ORA_DISK_1: restoring control file fromAUTOBACKUP /backup/c-1966040361-20141227-07
channel ORA_DISK_1: control file restore fromAUTOBACKUP complete
output filename=/u01/app/oracle/oradata/jfocp/control01.ctl
output filename=/u01/app/oracle/oradata/jfocp/control02.ctl
Finished restore at 27-DEC-14
后面的恢复步骤就省略了,和以第三种情况一样!!!
Control File and Server Parameter File Autobackup Options实验详细解析