Oracle 10G 归档模式下备份脚本

尊重原创,转载请注明出处,谢谢!www.wujianren.com

这是一个生产库的rman备份shell脚本,分为 0级备份 与1级差异累积备份,每周一次0级别备份,其他1级差异累积备份。(尊重原创,转载请标明出处http://blog.csdn.net/zonelan)

1、0级别备份shell 脚本:

[codesyntax lang=”oracle11″]

#!/bin/sh
#### 2011.6.27 ####
#level=0#
export TMP=/tmp
export TMPDIR=/tmp
export ORACLE_BASE=/opt/oracleonder
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=onder
export PATH=$PATH:$ORACLE_HOME/bin:
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export BAKFILE=/opt/bak/bak0.LOG
find /opt/bak/archbak -mtime +365 -name "arch*.tar.bz2" -EXEC rm -rf {} \;  ###因为每周只执行0级备份,归档日志不能自动删除(只有执行##全备,归档备份才会被设置为无效),所以这里写了一条命令来删除保存策略外的归档日志备份。
rman nocatalog target / msglog $BAKFILE << EOF
run{
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/opt/bak/conf_%F_%T.tar.bz2';
CONFIGURE RETENTION POLICY TO REDUNDANCY 20;
configure device TYPE disk parallelism 1 backup TYPE TO compressed backupset;
report obsolete;
DELETE noprompt obsolete;
crosscheck backup;
DELETE noprompt expired backup;
backup incremental LEVEL=0 DATABASE format '/opt/bak/bak_%T_%U_%t_%d.tar.bz2' plus archivelog format '/opt/bak/archbak/arch_%U_%s.tar.bz2';
DELETE noprompt ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-30';
crosscheck archivelog ALL;  ##检查出系统中不存在的归档日志记录,虽然上边的命令是删除超过30天的归档日志,但是相关记录记#录依然存在。
DELETE noprompt expired archivelog ALL;  ###noprompt 参数是不需要确认直接删除,用脚本必备。
}
EOF

[/codesyntax]

 

2、1级差异累积备份,差异累积备份的好处就是,故障恢复时只需要0级别+1级别 就可以了,不用像差异增量那样逐个叠加,方便恢复。

[codesyntax lang=”oracle11″]

#!/bin/sh
#### 2011.6.27 ####
#level=1#
export TMP=/tmp
export TMPDIR=/tmp
export ORACLE_BASE=/opt/oracleonder
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=onder
export PATH=$PATH:$ORACLE_HOME/bin:
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export BAKFILE=/opt/bak/bak1.LOG
rman nocatalog target / msglog $BAKFILE << EOF
run{
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/opt/bak/conf_%F_%T.tar.bz2';
CONFIGURE RETENTION POLICY TO REDUNDANCY 20;
configure device TYPE disk parallelism 1 backup TYPE TO compressed backupset;
report obsolete;
DELETE noprompt obsolete;
crosscheck backup;
DELETE noprompt expired backup;
backup incremental LEVEL=1 cumulative DATABASE format '/opt/bak/bak1_%T_%U_%t_%d.tar.bz2';
DELETE noprompt ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-30';
crosscheck archivelog ALL;  
DELETE noprompt expired archivelog ALL;  
}
EOF

[/codesyntax]

加入到crontab中即可

# m h  dom mon dow   command

30 00 * * 2 /root/rmana/ssh0.sh

30 00 * * 0,1,3,4,5,6 /root/rmana/ssh1.sh

发表评论