RMAN的实战篇--备份脚本

发布时间:2016-12-31 7:26:58编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"RMAN的实战篇--备份脚本 ",主要涉及到RMAN的实战篇--备份脚本 方面的内容,对于RMAN的实战篇--备份脚本 感兴趣的同学可以参考一下。

案列一、

目标:

1、每天夜间1 点执行;
2、数据库全备,同时备份控制文件及归档日志文件,备份文件保存至: /backup\目录下,并在完成归档日志文件备份后,自动删除已备份的归档日志;
3、备份保留7 天,过期则自动删除;
4、保留操作日志备查;

1. 编写RMAN脚本:

RUN{        CONFIGURE RETENTION POLICY TO  RECOVERY WINDOW OF 7 DAYS;        CONFIGURE CONTROLFILE AUTOBACKUP ON;        CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/%F';        ALLOCATE CHANNEL CH1 DEVICE TYPE DISK FORMAT '/backup/%U';        BACKUP DATABASE SKIP INACCESSIBLE FILESPERSET 10                PLUS ARCHIVELOG FILESPERSET 20                DELETE ALL INPUT;                RELEASE CHANNEL CH1;}ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;CROSSCHECK BACKUPSET;DELETE NOPROMPT OBSOLETE;

  SKIP INACCESSIBLE:表示跳过不可读的文件。

  SKIP OFFLINE:跳过offline 的数据文件;

  SKIP READONLY:跳过那些所在表空间为read-only 的数据文件;

2. 执行,并将输出日志重定向到指定文件

rman target/ msglog /home/oracle/Script/logs/`date +%F`.log cmdfile=/home/oracle/Script/orclDB_backup.rman 

3.检测结果

[[email protected] Script]$ ls /backup/0mro5acq_1_1              0oro5afm_1_1              0nro5ada_1_1              c-1458478724-20161223-00  [[email protected] Script]$ ls logs/2016-12-23.log

案列二、增量备份

##===========================================================  ##   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 programs    if [ -f ~/.bash_profile ];   then  . ~/.bash_profile  fi    ORACLE_SID=${1};                                      export ORACLE_SID      RMAN_LEVEL=${2};                                      export RMAN_LEVEL  TIMESTAMP=`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=/u02/database/${ORACLE_SID}/backup/rman/log      export RMAN_LOG     # Check rman level   #======================================================================  if [ "$RMAN_LEVEL" == "F" ];  then  unset INCR_LVL        BACKUP_TYPE=full  else        INCR_LVL="INCREMENTAL LEVEL ${RMAN_LEVEL}"        BACKUP_TYPE=lev${RMAN_LEVEL}   fi    RMAN_FILE=${RMAN_DATA}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP};       export RMAN_FILE  SSH_LOG=${RMAN_LOG}/${ORACLE_SID}_${BACKUP_TYPE}_${TIMESTAMP}.log;      export SSH_LOG  MAXPIECESIZE=4G;                                                    export MAXPIECESIZE    #Check RMAN Backup Path  #=========================================================================    if ! test -d ${RMAN_DATA}  then  mkdir -p ${RMAN_DATA}  fi  if [ ! -d  ${RMAN_LOG} ];thenmkdir -p ${RMAN_LOG}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 <<EOF  connect 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;  EOF RC=$?    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}.log  fi    #Remove old backup than 3 days  #============================================================================  RMDIR=${RMAN_DIR}/`/bin/date +%Y%m%d -d "3 days ago"`;   export RMDIR  echo >>${SSH_LOG}  echo -e "------Remove old backup than 3 days ------\n" >>${SSH_LOG}    if test -d ${RMDIR}      then      rm -rf ${RMDIR}      RC=$?  fi    echo >>${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}  fi  exit 

运行:

[[email protected] Script]$ sh  db_rman.sh orcl 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> [[email protected] Script]$

结果:

[[email protected] rman]$ ls20161228  log[[email protected] rman]$ ls 20161228/cntl_lev0.bak                            orcl_lev0_201612280027_arc_2qroidlp_1_1orcl_lev0_201612280027_2mroidj8_1_1      orcl_lev0_201612280027_c-1458478724-20161228-02orcl_lev0_201612280027_2nroidj9_1_1      orcl_lev0_201612280027_c-1458478724-20161228-03orcl_lev0_201612280027_arc_2proidlp_1_1  


上一篇:Creating Custom Login Screen In Oracle Forms 10g
下一篇:zz c++ Useful resources

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款