Oracle 11g R2 RAC RMAN备份脚本示例(2)

#!/bin/bash 
export ORACLE_BASE=/u01/app/oracle   
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1   
export ORACLE_SID=orcl1   
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK   
export PATH=$ORACLE_HOME/bin:$PATH   
LEVEL=$@   
DATE=`date +%w`   
DATE_2=`date +%Y%m%d`   
BACKUP_PATH="/data/rman_bak"   
BIN=$ORACLE_HOME/bin

if [ $# != 1 ]; then 
echo "usage: rman_bak.sh n   
where n is the rman backup level(Only 0,1 is permitted)."   
exit 1   
fi

if [ $@ -ne 0 -a $@ -ne 1 ]; then 
echo "usage: rman_bak.sh n   
where n is the rman backup level(Only 0,1 is permitted)."   
exit 2   
fi

if [[ $LEVEL = 0 ]]; then 
$BIN/rman log $BACKUP_PATH/logs/level.$ORACLE_SID.$LEVEL.$DATE_2.log <<EOF

connect target /; 
run{   
allocate channel c1 device type disk connect  'sys/oracle@orcl1';   
allocate channel c2 device type disk connect  'sys/oracle@orcl2';   
crosscheck backupset of archivelog all;   
backup archivelog  all format '$BACKUP_PATH/data/archlog.%d.level.$LEVEL.%U_%T' delete all input;   
delete noprompt expired backupset of archivelog all;   
release channel c1;   
release channel c2;   
}

run{ 
allocate channel c1 device type disk connect  'sys/oracle@orcl1';   
allocate channel c2 device type disk connect  'sys/oracle@orcl2';   
crosscheck backupset of database;   
backup incremental level $LEVEL database format '$BACKUP_PATH/data/data.%d.level.$LEVEL.%U_%T';   
backup spfile tag='spfile' format '$BACKUP_PATH/data/spfile_%U_%T';   
backup current controlfile tag='control' format='$BACKUP_PATH/data/control_%U_%T';   
delete noprompt expired backupset of database;   
delete noprompt obsolete;   
release channel c1;   
release channel c2;   
}   
exit;   
EOF

else

$BIN/rman log $BACKUP_PATH/logs/level.$ORACLE_SID.$LEVEL.$DATE_2.log <<EOF

connect target /; 
run{   
allocate channel c1 device type disk connect  'sys/oracle@orcl1';   
allocate channel c2 device type disk connect  'sys/oracle@orcl2';   
crosscheck backupset of archivelog all;   
backup archivelog all format '$BACKUP_PATH/data/archlog.%d.level.$LEVEL.%U_%T' delete all input;   
delete noprompt expired backupset of archivelog all;   
release channel c1;   
release channel c2;   
}

run{ 
allocate channel c1 device type disk connect  'sys/oracle@orcl1';   
allocate channel c2 device type disk connect  'sys/oracle@orcl2';   
crosscheck backupset of database ;   
backup incremental level $LEVEL database format '$BACKUP_PATH/data/data.%d.level.$LEVEL.%U_%T';   
backup spfile tag='spfile' format '$BACKUP_PATH/data/spfile_%U_%T';   
backup current controlfile tag='control' format='$BACKUP_PATH/data/control_%U_%T';   
delete noprompt expired backupset of database ;   
delete noprompt obsolete ;   
release channel c1;   
release channel c2;   
}

exit; 
EOF

fi

5. 手动执行测试

$ /u01/app/oracle/rman_bak/scripts/rman_bak.sh 0

测试注意细节:

1)观察rman log日志有无异常错误。 
2)观察archivelog是否有备份与删除。

Oracle数据库rman备份计划及恢复 

Oracle RMAN实现“一键式”表空间TSPITR 

Oracle 11gR2利用RMAN复制整库记录 

RMAN 配置归档日志删除策略

Oracle基础教程之通过RMAN复制数据库

RMAN备份策略制定参考内容

RMAN备份学习笔记

Oracle数据库备份加密 RMAN加密

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/dc0100bb140685b5cd946f720e3b4f7a.html