昨天去某客户部署RMAN备份,在跑shell脚本的时候,提示找不到归档日志,因为客户那里之前只对数据库做EXPDP逻辑导出备份,并且每天都自动删除前一天的归档,每个归档的生成量大概在200M左右,因为考虑磁盘空间比较紧张,不得已而为之。
在我的脚本中,是采用backup database format 'xxx' plus archivelog format 'xxx'的方式进行备份的,在执行RMAN脚本时,由于是先对归档日志进行备份,再对数据库进行备份的,在脚本的输出日志中,提示找不到35xxx的归档日志,而现在最旧的还物理存在的归档日志已经到36xxx了,也就是说,这1000多个日志其实是已经被OS脚本从物理上删除了,后来检验了一下确实如此,每天生成的归档数量大约为40个左右,那么一天的归档日志就是800M左右
于是进入RMAN对归档日志进行crosscheck,发现有7000多个归档日志检查结果是“failed”的(物理上已被删除),命令如下:
RMAN> crosscheck archivelog all;
再对这些expired的归档,从控制文件信息删除掉
RMAN> delete noprompt expired archivelog all;
然后再继续跑脚本,之后的备份就很顺利,先把归档日志备份完毕,接着是备份数据库,最后是控制文件和spfile
--------------------------------------推荐阅读 --------------------------------------
RMAN 配置归档日志删除策略
Oracle基础教程之通过RMAN复制数据库
RMAN备份策略制定参考内容
RMAN备份学习笔记
Oracle数据库备份加密 RMAN加密
--------------------------------------分割线 --------------------------------------
回来之后,我自己又做了一个测试,发现即便是当归档日志文件未failted的时候,备份还是顺利地进行下去了,下面看我自己的测试:
1. 先把归档日志移动到别的目录(模拟日志被物理删除)
[oracle@ora10g ~]$ cd $ORACLE_BASE/flash_recovery_area/ORA10G/archivelog
[oracle@ora10g archivelog]$ ll
total 8
drwxr-x--- 2 oracle oinstall 4096 Sep 24 11:46 2014_09_24
[oracle@ora10g archivelog]$
[oracle@ora10g archivelog]$ ll
total 6636
drwxr-x--- 2 oracle oinstall 4096 Sep 24 11:59 2014_09_24
这里共有8个归档日志文件被“删除”
2. 进入RMAN,对归档日志进行交叉校验
[oracle@ora10g archivelog]$ exit
exit
host command complete
RMAN> crosscheck archivelog all;
released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=145 devtype=DISK
validation for archived log
archive log filename=/u01/app/oracle/flash_recovery_area/ORA10G/archivelog/2014_09_24/o1_mf_1_3_b24gz52r_.arc recid=208 stamp=859116904
validation for archived log
archive log filename=/u01/app/oracle/flash_recovery_area/ORA10G/archivelog/2014_09_24/o1_mf_1_4_b24gz81d_.arc recid=209 stamp=859116904
validation for archived log
archive log filename=/u01/app/oracle/flash_recovery_area/ORA10G/archivelog/2014_09_24/o1_mf_1_5_b24gzbb6_.arc recid=210 stamp=859116906
validation for archived log
archive log filename=/u01/app/oracle/flash_recovery_area/ORA10G/archivelog/2014_09_24/o1_mf_1_6_b24gzd6y_.arc recid=211 stamp=859116908
validation for archived log
archive log filename=/u01/app/oracle/flash_recovery_area/ORA10G/archivelog/2014_09_24/o1_mf_1_7_b24gzky8_.arc recid=212 stamp=859116914
validation for archived log
archive log filename=/u01/app/oracle/flash_recovery_area/ORA10G/archivelog/2014_09_24/o1_mf_1_8_b24gzqnt_.arc recid=213 stamp=859116919
validation for archived log
archive log filename=/u01/app/oracle/flash_recovery_area/ORA10G/archivelog/2014_09_24/o1_mf_1_9_b24hjflc_.arc recid=214 stamp=859117453
validation for archived log
archive log filename=/u01/app/oracle/flash_recovery_area/ORA10G/archivelog/2014_09_24/o1_mf_1_10_b24ho39f_.arc recid=215 stamp=859117603
3. 不删除expired的归档,直接跑RMAN备份脚本
这次并没有报错并提示xxx归档找不到,而是直接就完成了备份,生成了备份集297,与在客户那里碰到的情况有出入
--备份完成后,查看生成的备份集
[oracle@ora10g ~]$ cd /u01/orabackup/backupsets/
[oracle@ora10g backupsets]$ ll -lrth
total 1.6G
-rw-r----- 1 oracle oinstall 606K Sep 24 12:00
-rw-r----- 1 oracle oinstall 166M Sep 24 12:02 ora10g-4175411955_20140924_859118425_298.db
-rw-r----- 1 oracle oinstall 610K Sep 24 12:02 ora10g-4175411955_20140924_859118562_299.arc
-rw-r----- 1 oracle oinstall 7.3M Sep 24 12:02 ora10g-c-4175411955-20140924-01.ctl
可以看到,备份全部完成了,共生成了2个归档日志备份集(arc),1个数据库备份集(db)以及控制文件备份集(ctl),这里有个细节要注意,由于我在脚本中写入了%s参数,从上面生成备份集生成的时间以及顺序可以发现RMAN备份这样一个顺序:
1. 对现有可以备份的数据库归档日志文件做一个备份
2. 对数据库进行备份
3. 切换一下日志,对完成全库备份后的归档日志再做一个备份(即使你没有通过RMAN> sql "alter system archive log current";来手动切)
4. 对控制文件备份(包括spfile,生成在同一个备份集)
我们可以看一下详细的日志输出,来对这个顺序有更深刻的了解:
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=11 recid=216 stamp=859118422
channel ORA_DISK_1: starting piece 1 at 24-914
channel ORA_DISK_1: finished piece 1 at 24-914
piece handle=/u01/orabackup/backupsets/ tag=ARC_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 24-914
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/ora10g/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/ora10g/sysaux01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/ora10g/undotbs01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/ora10g/example01.dbf
input datafile fno=00006 name=/u01/app/oracle/oradata/ora10g/zlm01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/ora10g/users01.dbf
channel ORA_DISK_1: starting piece 1 at 24-914
channel ORA_DISK_1: finished piece 1 at 24-914
piece handle=/u01/orabackup/backupsets/ tag=DB_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:16
Finished backup at 24-914
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=12 recid=217 stamp=859118561
channel ORA_DISK_1: starting piece 1 at 24-914
channel ORA_DISK_1: finished piece 1 at 24-914
piece handle=/u01/orabackup/backupsets/ tag=ARC_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 24-914
piece handle=/u01/orabackup/backupsets/ comment=NONE
Finished Control File and SPFILE Autobackup at 24-914
更多详情见请继续阅读下一页的精彩内容: