這里我的備份的策略,還是比較常見(jiàn)的策略。這里不需要?jiǎng)?chuàng)新,公眾的經(jīng)驗(yàn)是進(jìn)過(guò)市場(chǎng)和現(xiàn)實(shí)的考驗(yàn)的。
備份策略:
星期天做0級(jí)備份
星期一,星期四做一級(jí)增量備份
星期二,星期三,星期五,星期六做二級(jí)增量備份,
這樣的備份要要要恢復(fù)到任何一個(gè)時(shí)刻,都可以很方便的找到我們需要的恢復(fù)文件。
策略定下來(lái)了,下面就是我們的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
再來(lái)看看我們的備份的腳本吧
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."
聯(lián)系客服