#script.:Backup.sh #creater:BG9FQP ################################################# ############### 需要修改参数的区域 ############### # 数据库SID O_SID=orcl # Oracle 安装路径 ORACLE_BASE=/u01/app/oracle ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/dbhome_1 # 备份路径- 最后不需要“/” BACKUP_DATA_DIR=/backup/bak # 备份保留时间 KEEP_TIME=30 ################# 需要修改参数的区域 ############### ################################################# #Backup level # 根据需求 设置周几做 全备份,周几做增量。 # 全量备份 选0 # 增量备份 选1 # 默认 周六全备份,其他增量 WEEK_DAILY=`date +%a` case "$WEEK_DAILY" in "Mon") BAK_LEVEL=1 ;; "Tue") BAK_LEVEL=1 ;; "Wed") BAK_LEVEL=1 ;; "Thu") BAK_LEVEL=1 ;; "Fri") BAK_LEVEL=1 ;; "Sat") BAK_LEVEL=0 ;; "Sun") BAK_LEVEL=1 ;; "*") BAK_LEVEL=error esac export BAK_LEVEL=$BAK_LEVEL ################# 需要修改参数的区域 ############### ################################################# # 删除备份30天之前的 find ${BACKUP_DATA_DIR} -mtime +${KEEP_TIME} -name "*.*" -exec rm -Rf {} \; #Get date and hour 拿系统时间 DATE_H=`date '+%Y-%m-%d-%H'` DATE_D=`date '+%Y-%m-%d'` #Backup dir 备份文件存储路径 BAK_DIR=${BACKUP_DATA_DIR}"/"$DATE_D"/" #Log dir # 备份脚本日志目录和名字 RMAN_LOG_DIR="/home/oracle/log/"$DATE_D"/" RMAN_LOG_FILE=$RMAN_LOG_DIR$DATE_H"_"${O_SID}".log" SUMMARY_LOG="/home/oracle/log/backup_"${O_SID}"_summary.log" #Oracle env export ORACLE_BASE=${ORACLE_BASE} export ORACLE_SID=${O_SID} export ORACLE_HOME=${ORACLE_HOME} export PATH=$ORACLE_HOME/bin:$PATH # 创建相关目录 # 检查日志目录 if ! test -d ${RMAN_LOG_DIR} then mkdir -p ${RMAN_LOG_DIR} fi # 检查备份路径 if ! test -d ${BAK_DIR} then mkdir -p ${BAK_DIR} fi # 备份日志文件输出 echo " " >>${SUMMARY_LOG} echo "------"${DATE_D}"-------level "${BAK_LEVEL}" --------------------" >>${SUMMARY_LOG} echo " " >>${SUMMARY_LOG} echo "Rman Begin to Working ........." >>${SUMMARY_LOG} echo "Begin time at:" `date` --`date +%Y%m%d%H%M` >>${SUMMARY_LOG} echo "Today is : $WEEK_DAILY incremental level= $BAK_LEVEL">>$RMAN_LOG_FILE #database backup rman target / nocatalog msglog $RMAN_LOG_FILE append <<EOF configure encryption for database off; set encryption off; run{ CONFIGURE BACKUP OPTIMIZATION OFF; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '${BAK_DIR}con_%F'; crosscheck archivelog all; delete expired archivelog all; allocate channel c1 type disk; allocate channel c2 type disk; backup incremental level ${BAK_LEVEL} tag 'backup_db_level_${BAK_LEVEL}' format='${BAK_DIR}bk_%s_%p_%t' database; sql 'alter system archive log current'; backup filesperset 2 format '${BAK_DIR}al_%s_%p_%t' archivelog ALL DELETE INPUT; backup current controlfile tag='bak_ctlfile' format='${BAK_DIR}cntrl_%s_%p_%t'; backup spfile tag='spfile' format='${BAK_DIR}spfile_%s_%p_%t'; release channel c1; release channel c2; } EOF RC=$? echo "Rman Stop working @ time:"`date` `date +%Y%m%d%H%M` >>${SUMMARY_LOG} echo "------------------------" >>${SUMMARY_LOG} #check rman status if [ $RC -ne "0" ]; then echo "------ rman backup error ------" >>${SUMMARY_LOG} tail ${RMAN_LOG_FILE} >> ${SUMMARY_LOG} echo " " >>${SUMMARY_LOG} else echo "------ No error found during RMAN backup peroid------" >>${SUMMARY_LOG} fi echo "------------------------" >>${SUMMARY_LOG} echo "------------------------" >>${SUMMARY_LOG}