程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> OracleRman備份腳本與自動刪除重復備份文件

OracleRman備份腳本與自動刪除重復備份文件

編輯:Oracle教程

OracleRman備份腳本與自動刪除重復備份文件


#!/bin/sh
source /home/oracle/.bash_profile


if [ -z $1 ]
then
  echo "Please Input a number,Usage: 0|1|2"
  exit
else
  RMAN_LEVEL=$1
fi


export ORACLE_SID=xxxx
export TODAY=`date '+%Y%m%d'`
export RMAN_DIR=/backup/archivelog/rman/$ORACLE_SID/$TODAY-$RMAN_LEVEL




mkdir -p $RMAN_DIR
cd $RMAN_DIR
LogFile=ora_rman_bk_$ORACLE_SID-L$RMAN_LEVEL-`date '+%Y%m%d'`.log


# rman backup 
rman target /  msglog=$RMAN_DIR/$LogFile<<EOF
delete noprompt obsolete; 
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '$RMAN_DIR/cf%F';
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
backup as compressed backupset incremental level $RMAN_LEVEL filesperset 3 tag 'dbL$RMAN_LEVEL' format '$RMAN_DIR/ora_o_%d_%t%s%p%u'
 database skip readonly include current controlfile;
sql 'alter system archive log current' ;
backup(archivelog all format '$RMAN_DIR/ora_a_%d_%t%s%p%u' delete input);
release channel c1;
release channel c2;
}


list backup;
exit;
EOF


#mail backup log
mail -s "$ORACLE_SID rman L$RMAN_LEVEL backup log $TODAY"  [email protected] < $RMAN_DIR
/$LogFile



順便提一嘴:

delete noprompt obsolete與delete obsolete區別

noprompt :是不用提示,在shell腳本中不需要對發起的delete命令進行“yes or no”的確認。



在crontab 中設置如下: 0 4 * * 5 sh /backup/scripts/oracle/oracle_rman_bak.sh 0 > /backup/archivelog/logs/rman.log 2>&1
0 4 * * 2 sh /backup/scripts/oracle/oracle_rman_bak.sh 1 > /backup/archivelog/logs/rman.log 2>&1

進行一周一次增量與0級備份。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved