此备份脚本整理自网络,再此只是添加了些注释。此脚本思路清晰,稍做更改便可应用到生产机上。
1 #!/bin/bash 2 ####################################################################### 3 # 4 # 备份策略: 5 # 每周日凌晨做0级备份, 6 # 每周一,四做一级备份, 7 # 每周二,三,五,六做二级备份, 8 # 00 4 * * 0 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 0 9 # 00 4 * * 1,4 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 1 10 # 00 4 * * 2,3,5,6 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 2 11 # 12 ####################################################################### 13 #备份脚本: 14 #set env 15 #环境变量根据 实际情况自行修改 16 export ORACLE_BASE=/u01/app/oracle 17 export ORACLE_HOME=$ORACLE_BASE/db10g 18 export ORACLE_SID=emar 19 export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK 20 export PATH=$ORACLE_HOME/bin:$PATH 21 22 DATE=`date +%w` 23 DATE_2=`date +%Y%m%d` 24 BACKUP_PATH=/u01/app/oracle/rman_bak 25 #传进来的参数:备份级别 26 LEVEL=$@ 27 TARGET_SID=emar 28 RMAN_SID=emar.emar 29 BIN=/u01/app/oracle/db10g/bin 30 31 # Delete the data backuped last time 此处根据保留备份时间自行修改 32 #rm -rf $BACKUP_PATH/data/$DATE/* 33 34 if [ $# != 1 ]; then 35 echo "usage: rman_bak.sh n 36 where n is the rman backup level(0,1,2 is permitted)." 37 exit 1 38 fi 39 40 if [ $@ -ne 0 -a $@ -ne 1 -a $@ -ne 2 ]; then 41 echo "usage: rman_bak.sh n 42 where n is the rman backup level(Only 0,1,2 is permitted)." 43 exit 2 44 fi 45 46 echo "-----------------------------start-----------------------------";date 47 48 #0级备份,调用rman时利用了here document 49 if [ $LEVEL = 0 ]; then 50 51 $BIN/rman log $BACKUP_PATH/log/level.$TARGET_SID.$LEVEL.$DATE_2.log <