RMAN-06091分析备份脚本的存在问题

2021-11-15 00:00:00 修改 执行 操作 备份 脚本


近遇到一个问题,一个数据库的备份目录/backup满了,导致后续备份无法写入,再检查日志时发现错误
delete obsolete
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of delete command at 11/10/2021 17:28:02
RMAN-06091: no channel allocated for maintenance (of an appropriate type)


我们先分析这个错误RMAN-06091说明对于备份到不同介质的备份,执行Delete obsolete操作时刻
没有分配channel.我们可以使用list backup指令查看备份是否在disk或者磁带上。然后通过如下指令解决
备份在磁盘:
RMAN> allocate channel for maintenance type disk;
备份在磁带:parms参数根据实际情况修改
allocate channel t1 device type sbt parms='SBT_LIBRARY=oracle.disksbt, ENV=(BACKUP_DIR=/tmp)';
然后再执行delete obsolete操作
即如果是单独执行使用如下指令配合
RMAN> allocate channel for maintenance type disk;
RMAN> delete obsolete device type disk;

如果是run{} 执行块,需要在执行块中增加分配通道的步骤,如下是原始脚本
#!/bin/bash
source /export/home/oracle/.profile
day=`date -u +%Y%m%d`
rman target / > /backup/log/bk_level2_$day.log <<EOF
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 2 database tag='datafile_bak' format '/backup/datafile/level2_%U_%T.bkp';
sql 'alter system archive log current';
backup archivelog all tag='arch_bak' format '/backup/archivelog/arch_%U_%T.bkp' delete input;
backup current controlfile tag='bak_ctl' format ='/backup/controlfile/ctl_file_%U_%T.bkp';
backup spfile tag='spfile' format ='/backup/spfile/spfile_%U_%T.bkp';
delete noprompt expired backup;
delete noprompt obsolete device type disk;
release channel d1;
release channel d2;
}
allocate channel for maintenance device type disk;
delete noprompt obsolete redundancy 1 device type disk;
exit;
EOF

在run{}块中分配了两个通道用户备份,但是在delete操作时没有分配通道,所以run{}部分报错。这个报错
得原因就是没有channel,所以在之前脚本修改如下
delete noprompt expired backup;
allocate channel for maintenance device type disk;
delete noprompt obsolete device type disk;

如果你细心也会发现这个脚本其实还有其他问题就是delete noprompt expired backup这个操作需要crosscheck
所以我们可以如下修改
crosscheck backup;
delete noprompt expired backup;
allocate channel for maintenance device type disk;
delete noprompt obsolete device type disk;

再继续看脚本其实,我们发现再run{}后有如下删除obsolete操作
allocate channel for maintenance device type disk;
delete noprompt obsolete redundancy 1 device type disk;
所以run{}中得delete obsolete是没有必要得。
所以我们可以如下修改脚本
#!/bin/bash
source /export/home/oracle/.profile
day=`date -u +%Y%m%d`
rman target / > /backup/log/bk_level2_$day.log <<EOF
run{
allocate channel d1 type disk;
allocate channel d2 type disk;
backup incremental level 2 database tag='datafile_bak' format '/backup/datafile/level2_%U_%T.bkp';
sql 'alter system archive log current';
backup archivelog all tag='arch_bak' format '/backup/archivelog/arch_%U_%T.bkp' delete input;
backup current controlfile tag='bak_ctl' format ='/backup/controlfile/ctl_file_%U_%T.bkp';
backup spfile tag='spfile' format ='/backup/spfile/spfile_%U_%T.bkp';
crosscheck backupset;
delete noprompt expired backup;
release channel d1;
release channel d2;
}
allocate channel for maintenance device type disk;
delete noprompt obsolete redundancy 1 device type disk;
exit;
EOF

再次执行脚本,没有之前的609错误。

相关文章