这里我的备份的策略,还是比较常见的策略。这里不需要创新,公众的经验是进过市场和现实的考验的。
备份策略:
星期天做0级备份
星期一,星期四做一级增量备份
星期二,星期三,星期五,星期六做二级增量备份,
这样的备份要要要恢复到任何一个时刻,都可以很方便的找到我们需要的恢复文件。
策略定下来了,下面就是我们的crontab了
00 4 * * 0 $ORACLE_BASE/admin/$ORACLE_SID/rman/scripts/do_rman.sh 0
00 4 * * 1,4 $ORACLE_BASE/admin/$ORACLE_SID/rman/scripts/do_rman.sh 1
00 4 * * 2,3,5,6 $ORACLE_BASE/admin/$ORACLE_SID/rman/scripts/do_rman.sh 2
再来看看我们的备份的脚本吧
do_rman.sh
#!/bin/bash
#set env
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export PATH=$ORACLE_HOME/bin:$PATH
TARGET_SID=$TARGET_SID
RMAN_SID=$RMAN_SID
export PATH=$ORACLE_HOME/bin:$PATH
DATE=`date +%w`
DATE_2=`date +%Y%m%d`
BACKUP_PATH=$ORACLE_BASE/admin/$ORACLE_SID/rman/backup
LEVEL=$@
BIN=$ORACLE_HOME/bin
# Delete the data backuped last time
rm -rf $BACKUP_PATH/data/$DATE/*
if [ $# != 1 ]; then
echo "usage: do_rman.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: do_rman.sh n
where n is the rman backup level(Only 0,1,2 is permitted)."
exit 2
fi
echo "[do_rman] rman is starting."
if [ $LEVEL = 0 ]; then
$BIN/rman log $BACKUP_PATH/log/level.$TARGET_SID.$LEVEL.$DATE_2.log <<EOF
connect target /;
connect catalog rman/rman@$RMAN_SID;
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 <<EOF
connect target sys/sys202;
connect catalog rman/rman@$RMAN_SID;
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
echo "[do_rman] rman is success."