代码改变世界

为什么 RMAN 控制文件自动备份的名称格式没有遵循 %F 规则

2019-06-10 06:39  askscuti  阅读(662)  评论(0编辑  收藏  举报

 

在 Oracle 中越是简单的问题,往往越难找到答案,举个例子:

你是否留意观察过在 RMAN 进行备份的时候,自动生成的控制文件名称是否是按照 %F 规则来生成的?

关于控制文件自动备份路径格式,在另一篇博文中有详细介绍,点我查看。来自博客园 AskScuti

目录

1. 查看默认 RMAN 配置

2. 备份观察控制文件备份片名称

3. 为什么没有按照 %F 规则生成

 

1. 查看默认 RMAN 配置

RMAN> show all;

RMAN configuration parameters for database with db_unique_name PROD1 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 '%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
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_PROD1.f'; # default

2. 备份观察控制文件名称

控制文件自动备份已经打开,且格式遵循 %F 命名,尝试备份 4 号文件

RMAN> backup datafile 4 format '/u01/app/oracle/backup/%s_%d_%U.d4';

Starting backup at 2019-06-08 21:11:35
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2019-06-08 21:11:35
channel ORA_DISK_1: finished piece 1 at 2019-06-08 21:11:36
piece handle=/u01/app/oracle/backup/6_PROD1_06u3k3o7_1_1.d4 tag=TAG20190608T211135 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2019-06-08 21:11:36

Starting Control File and SPFILE Autobackup at 2019-06-08 21:11:36
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/autobackup/2019_06_08/o1_mf_s_1010437896_ghqf098j_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2019-06-08 21:11:37

注意控制文件自动备份,生成出来的名称:o1_mf_s_1010437896_ghqf098j_.bkp

有同学说你讲的 %F 命名规则明明是这样:c-IIIIIIIIII-YYYYMMDD-QQ

为什么生成出来却是这样:o1_mf_s_1010437896_ghqf098j_.bkp

3. 为什么没有按照 %F 规则生成

没有按照 %F 规则生成的原因是:默认情况下,控制文件自动备份的路径为闪回区,因此在默认闪回区里面生成的控制文件名称不遵循 %F 的命名方式,即使 RMAN 配置了 %F。

我们可以修改 RMAN 控制文件默认路径配置,例如

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/oracle/backup/%d_%F';

new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/app/oracle/backup/%d_%F';
new RMAN configuration parameters are successfully stored

再次进行备份查看控制文件生成的名称

RMAN> backup datafile 4;

Starting backup at 2019-06-08 21:20:36
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2019-06-08 21:20:36
channel ORA_DISK_1: finished piece 1 at 2019-06-08 21:20:37
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/backupset/2019_06_08/o1_mf_nnndf_TAG20190608T212036_ghqfk4n7_.bkp tag=TAG20190608T212036 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2019-06-08 21:20:37

Starting Control File and SPFILE Autobackup at 2019-06-08 21:20:37
piece handle=/u01/app/oracle/backup/PROD1_c-2202758063-20190608-01 comment=NONE
Finished Control File and SPFILE Autobackup at 2019-06-08 21:20:38

这时候,控制文件名称就遵循了 %F 的格式。

注意:在指定控制文件自动备份路径的时候,格式 %F 是强制必须指定的,否则显示错误 RMAN-06492: control file AUTOBACKUP format "xxxx" must specify a "%F" format specifier