ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 一个较完整的RMAN增量备份脚本

一个较完整的RMAN增量备份脚本

原创 Linux操作系统 作者:shilei1 时间:2011-12-19 13:15:44 0 删除 编辑

把最近刚改写完成的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 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 <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
$BIN/exp rman/rman@$RMAN_SID 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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2018-10-10

  • 博文量
    534
  • 访问量
    8232