一個較完整的RMAN增量備份指令碼

shilei1發表於2011-12-19

把最近剛改寫完成的RMAN增量備份指令碼貼上來,經過幾天的測試基本執行良好,下一步可以在生產庫上用了,測試過程中特別增加了儘量節約空間的考慮(磁碟空間不是很冗餘),


備份策略:
每週日凌晨做0級備份,
每週一,四做一級備份,
每週二,三,五,六做二級備份,
00 4 * * 0 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 0
00 4 * * 1,4 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 1
00 4 * * 2,3,5,6 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 2
備份指令碼:
#!/bin/bash
#set env
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/db10g
export ORACLE_SID=emar
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export PATH=$ORACLE_HOME/bin:$PATH
DATE=`date +%w`
DATE_2=`date +%Y%m%d`
BACKUP_PATH=/u01/app/oracle/rman_bak
LEVEL=$@
TARGET_SID=emar
RMAN_SID=emar.emar
BIN=/u01/app/oracle/db10g/bin
# Delete the data backuped last time
rm -rf $BACKUP_PATH/data/$DATE/*

if [ $# != 1 ]; then
echo "usage: rman_bak.sh n
where n is the rman backup level(0,1,2 is permitted)."
exit 1
fi
if [ $@ -ne 0 -a $@ -ne 1 -a $@ -ne 2 ]; then
echo "usage: rman_bak.sh n
where n is the rman backup level(Only 0,1,2 is permitted)."
exit 2
fi
echo "-----------------------------start-----------------------------";date
if [ $LEVEL = 0 ]; then
$BIN/rman log $BACKUP_PATH/log/level.$TARGET_SID.$LEVEL.$DATE_2.log <connect target sys/sys202;
connect catalog ;
resync catalog;
run{
allocate channel c1 type disk ;
crosscheck backupset of archivelog all ;
backup filesperset 3 format '$BACKUP_PATH/data/$DATE/arch.%d.live.$LEVEL.%t'(archivelog from time 'sysdate-7' all delete input) ;
delete noprompt expired backupset of archivelog all ;
release channel c1 ;
}

run{
allocate channel c2 type disk ;
crosscheck backupset of database ;
backup incremental level $LEVEL filesperset 3 format '$BACKUP_PATH/data/$DATE/data.%d.live.$LEVEL.%t'(database include current controlfile) ;
delete noprompt expired backupset of database ;
delete noprompt obsolete ;
release channel c2 ;
}
exit;
EOF

else
$BIN/rman log $BACKUP_PATH/log/level.$TARGET_SID.$LEVEL.$DATE_2.log <connect target sys/sys202;
connect catalog ;
resync catalog;
run{
allocate channel c1 type disk ;
crosscheck backupset of archivelog all ;
backup filesperset 3 format '$BACKUP_PATH/data/$DATE/arch.%d.live.$LEVEL.%t' (archivelog from time 'sysdate-1' all) ;
delete noprompt expired backupset of archivelog all ;
release channel c1 ;
}

run{
allocate channel c2 type disk ;
crosscheck backupset of database ;
backup incremental level $LEVEL filesperset 3 format '$BACKUP_PATH/data/$DATE/data.%d.live.$LEVEL.%t' (database include current controlfile) ;
delete noprompt expired backupset of database ;
delete noprompt obsolete ;
release channel c2 ;
}

exit;
EOF

fi
$BIN/exp file=$BACKUP_PATH/data/$DATE/live.rman.$DATE_2.dmp log=$BACKUP_PATH/log/$RMAN_SID.rman.$DATE_2.log
echo "------------------------------end------------------------------";date

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/196700/viewspace-713581/,如需轉載,請註明出處,否則將追究法律責任。

相關文章