RMAN備份對於Oracle資料庫的備份與恢複簡單易用,成本低廉。對於使用非catalog方式而言,將RMAN指令碼嵌入到shell指令碼,然後再通過crontab來實現中小型資料庫Database Backup無疑是首選。本文提供了一個簡單易用的基於linux shell下的RMAN備份指令碼供參考。大家可根據自己的需要進行適當調整。
RMAN備份相關方面的知識較多,可以參考:
RMAN 概述及其體繫結構
RMAN 配置、監控與管理
RMAN 備份詳解
RMAN 還原與恢複
RMAN catalog 的建立和使用
基於catalog 建立RMAN儲存指令碼
基於catalog 的RMAN 備份與恢複
RMAN 備份路徑困惑
其次是對於shell指令碼中調用sql,rman語句可以參考
Linux/Unix shell 指令碼中調用SQL,RMAN指令碼
Linux/Unix shell sql 之間傳遞變數
下面是指令碼的具體內容
##===========================================================## db_bak_rman.sh ## created by Robinson ## 2011/11/07 ## usage: db_bak_rman.sh <$ORACLE_SID> <$BACKUP_LEVEL>## BACKUP_LEVEL: ## F: full backup## 0: level 0## 1: level 1 ##============================================================#!/bin/bash# User specific environment and startup programsif [ -f ~/.bash_profile ]; then. ~/.bash_profilefiORACLE_SID=${1}; export ORACLE_SID RMAN_LEVEL=${2}; export RMAN_LEVELTIMESTAMP=`date +%Y%m%d%H%M`; export TIMESTAMP DATE=`date +%Y%m%d`; export DATE RMAN_DIR=/u02/database/${ORACLE_SID}/backup/rman; export RMAN_DIR RMAN_DATA=${RMAN_DIR}/${DATE}; export RMAN_DATA #RMAN_LOG=$RMAN_DATA/log; export RMAN_LOG RMAN_LOG=/u02/database/${ORACLE_SID}/backup/rman/log export RMAN_LOG # Check rman level #======================================================================if [ "$RMAN_LEVEL" == "F" ];then unset INCR_LVL BACKUP_TYPE=fullelse INCR_LVL="INCREMENTAL LEVEL ${RMAN_LEVEL}" BACKUP_TYPE=lev${RMAN_LEVEL} fiRMAN_FILE=${RMAN_DATA}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}; export RMAN_FILESSH_LOG=${RMAN_LOG}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}.log; export SSH_LOGMAXPIECESIZE=4G; export MAXPIECESIZE#Check RMAN Backup Path#=========================================================================if ! test -d ${RMAN_DATA}thenmkdir -p ${RMAN_DATA}fiecho "---------------------------------" >>${SSH_LOG}echo " " >>${SSH_LOG}echo "Rman Begin to Working ........." >>${SSH_LOG}echo "Begin time at:" `date` --`date +%Y%m%d%H%M` >>${SSH_LOG}#Startup rman to backup #=============================================================================$ORACLE_HOME/bin/rman log=${RMAN_FILE}.log <<EOFconnect target /run {CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 3 DAYS;CONFIGURE BACKUP OPTIMIZATION ON;CONFIGURE CONTROLFILE AUTOBACKUP ON;CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${RMAN_FILE}_%F';ALLOCATE CHANNEL 'ch1' TYPE DISK maxpiecesize=${MAXPIECESIZE};ALLOCATE CHANNEL 'ch2' TYPE DISK maxpiecesize=${MAXPIECESIZE};set limit channel ch1 readrate=10240;set limit channel ch1 kbytes=4096000;set limit channel ch2 readrate=10240;set limit channel ch2 kbytes=4096000;CROSSCHECK ARCHIVELOG ALL;DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;BACKUP #AS COMPRESSED BACKUPSET ${INCR_LVL}DATABASE FORMAT '${RMAN_FILE}_%U' TAG '${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}';SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';BACKUP ARCHIVELOG ALL FORMAT '${RMAN_FILE}_arc_%U' TAG '${ORACLE_SID}_arc_${TIMESTAMP}'DELETE INPUT;DELETE NOPROMPT OBSOLETE;RELEASE CHANNEL ch1;RELEASE CHANNEL ch2;}sql "alter database backup controlfile to ''${RMAN_DATA}/cntl_${BACKUP_TYPE}.bak''";exit;EOFRC=$?cat ${RMAN_FILE}.log >>${SSH_LOG}echo "Rman Stop working @ time:"`date` `date +%Y%m%d%H%M` >>${SSH_LOG}echo >>${SSH_LOG}echo "------------------------" >>${SSH_LOG}echo "------ Disk Space ------" >>${SSH_LOG}df -h >>${SSH_LOG}echo >>${SSH_LOG}if [ $RC -ne "0" ]; then echo "------ error ------" >>${SSH_LOG}else echo "------ no error found during RMAN backup peroid------" >>${SSH_LOG} rm -rf ${RMAN_FILE}.logfi#Remove old backup than 3 days#============================================================================RMDIR=${RMAN_DIR}/`/bin/date +%Y%m%d -d "3 days ago"`; export RMDIRecho >>${SSH_LOG}echo -e "------Remove old backup than 3 days ------\n" >>${SSH_LOG}if test -d ${RMDIR} then rm -rf ${RMDIR} RC=$?fiecho >>${SSH_LOG}if [ $RC -ne "0" ]; then echo -e "------ Remove old backup exception------ \n" >>${SSH_LOG}else echo -e "------ no error found during remove old backup set peroid------ \n" >>${SSH_LOG}fiexitoracle@SZDB:~/robinson/scripts/dba_scripts/custom/sql> ./db_bak_rman.sh GOBO1 0RMAN> RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15> 16> 17> 18> 19> 20> 21> 22> 23> 24> RMAN> RMAN> oracle@SZDB:~/robinson/scripts/dba_scripts/custom/sql>oracle@SZDB:/u02/database/GOBO1/backup/rman> ls20120928 logoracle@SZDB:/u02/database/GOBO1/backup/rman/20120928> lscntl_lev0.bak GOBO1_lev0_201209281421_arc_4onmb9ro_1_1GOBO1_lev0_201209281421_4knmb9jn_1_1 GOBO1_lev0_201209281421_c-733951103-20120928-00GOBO1_lev0_201209281421_4lnmb9jn_1_1 GOBO1_lev0_201209281421_c-733951103-20120928-01GOBO1_lev0_201209281421_arc_4nnmb9rn_1_1
更多參考:
有關基於使用者管理的備份和備份恢複的概念請參考
Oracle 冷備份
Oracle 熱備份
Oracle 備份恢複概念
Oracle 執行個體恢複
Oracle 基於使用者管理恢複的處理(詳細描述了介質恢複及其處理)
SYSTEM 資料表空間管理及備份恢複
SYSAUX資料表空間管理及恢複
Oracle 基於備份控制檔案的恢複(unsing backup controlfile)
有關RMAN的備份恢複與管理請參考
RMAN 概述及其體繫結構
RMAN 配置、監控與管理
RMAN 備份詳解
RMAN 還原與恢複
RMAN catalog 的建立和使用
基於catalog 建立RMAN儲存指令碼
基於catalog 的RMAN 備份與恢複
RMAN 備份路徑困惑
有關ORACLE體繫結構請參考
Oracle 資料表空間與資料檔案
Oracle 密碼檔案
Oracle 參數檔案
Oracle 聯機重做記錄檔(ONLINE LOG FILE)
Oracle 控制檔案(CONTROLFILE)
Oracle 歸檔日誌
Oracle 復原(ROLLBACK)和撤銷(UNDO)
Oracle 資料庫執行個體啟動關閉過程
Oracle 10g SGA 的自動化管理
Oracle 執行個體和Oracle資料庫(Oracle體繫結構)