#!/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是否有备份与删除。

