ITPub博客

首页 > 数据库 > Oracle > rman备份策略

rman备份策略

原创 Oracle 作者:dbs101 时间:2011-06-30 20:14:27 0 删除 编辑

配置控制文件保留时间为14天,这里的例子是保持7天的备份。
alter system set CONTROL_FILE_RECORD_KEEP_TIME = 14 scope=both;

配置rman的保留策略为保留7天,这是为了删除多余的备份。具体含义是保留能恢复到7天前
所有的必须的备份。
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

07/03 - 0 level backup (星期天)
07/04 - 1 level backup
07/05 - 1 level backup
07/06 - 1 level backup
07/07 - 1 level backup
07/08 - 1 level backup
07/09 - 1 level backup
07/10 - 0 level backup (星期天)
07/11 - 1 level backup
07/12 - 1 level backup
07/13 - 1 level backup --current day

如果今天是07/13,那么需要保留能恢复到07/06的所有的备份。07/06的备份时1 level backup,
恢复时需要从0 level backup开始,所以需要保留07/03的0 level backup。

配置block change tracking, 这个功能是10g引入的,在增量备份时,只扫描那些更改的块。
启用这个功能需要观察是否影响数据库的性能。
alter database enable block change tracking;

select * from v$block_change_tracking;

下面的算法是计算block change tracking文件的大小。
SELECT((
(SELECT SUM(ceil(bytes /(7686 * 1024 * 1024))) * 8 bitmap_ext
FROM v$datafile) +
(SELECT ceil(VALUE / 252) file_descr_ext
FROM v$parameter
WHERE name = 'db_files') + 1)
* 32 + 1088) / 1024 bct_file_size_mb
FROM dual;

这个功能相应的等待事件:
select * from v$system_event where lower(event) like '%track%'
change tracking file synchronous read
change tracking file synchronous write
block change tracking buffer space

BCT只支持8 versions的tracking,如果增量备份超过了8次,那么在增量备份时,需扫描整
个数据库。

每个星期0级备份
0 1 * * 0 /u03/rman/back_level0.sh

每天1级增量备份
0 1 * * 1,2,3,4,5,6 /u03/rman/back_level1.sh

每天删除过期备份
0 2 * * 1,2,3,4,5,6 /u03/rman/remove_expired_back.sh

[oracle@dbs101 rman]$ more back_level0.sh
#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_SID=dbs101
$ORACLE_HOME/bin/rman target / cmdfile /u03/rman/back_level0.rcv >>/u03/rman/back_level0.log

[oracle@dbs101 rman]$ more back_level0.rcv
run {
allocate channel 'dev1' type disk;
backup incremental level 0  tag 'dbL0' format '/u03/backup/basic%u_%s_%p_%t' AS COMPRESSED BACKUPSET database skip
 readonly;
sql 'alter system archive log current' ;
backup filesperset 3 format '/u03/backup/arch%u_%s_%p_%t' AS COMPRESSED BACKUPSET archivelog all delete input;
backup current controlfile format '/u03/backup/contr%u_%s_%p_%t';
release channel dev1;
}

[oracle@dbs101 rman]$ more back_level1.sh
#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_SID=dbs101
$ORACLE_HOME/bin/rman target / cmdfile /u03/rman/back_level1.rcv >>/u03/rman/back_level1.log

[oracle@dbs101 rman]$ more back_level1.rcv
run {
allocate channel 'dev1' type disk   ;
DELETE BACKUP COMPLETED BEFORE 'SYSDATE-7' DEVICE TYPE DISK;
backup incremental level 1  tag 'dbL1' format '/u03/backup/basic%u_%s_%p_%t' AS COMPRESSED BACKU
PSET database skip readonly;
sql 'alter system archive log current' ;
backup filesperset 3 format '/u03/backup/arch%u_%s_%p_%t' AS COMPRESSED BACKUPSET archivelog all delete input;
backup current controlfile format '/u03/backup/contr%u_%s_%p_%t';
DELETE ARCHIVELOG UNTIL TIME 'SYSDATE-7';
release channel dev1;
}

[oracle@dbs101 rman]$ more remove_expired_back.sh
#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_SID=dbs101
$ORACLE_HOME/bin/rman target / cmdfile /u03/rman/remove_expired_back.rcv >>/u03/rman/remove_expired_back.log

[oracle@dbs1 rman]$ more remove_expired_back.rcv
run {
allocate channel 'dev1' type disk;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
restore database validate;
restore archivelog all validate;
release channel dev1;
}

--backup log file per day


rq=`date +"%Y%m%d"`
tar cPvfz /u03/rman/log/backup$rq.tar.gz /u03/rman/*.log
rm /u03/rman/*.log


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25105315/viewspace-701086/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-12-18

  • 博文量
    92
  • 访问量
    446700