zoukankan      html  css  js  c++  java
  • Oracle数据库定时增量备份脚本

    创建一个目录放备份脚本

    mkdir rman_scripts
    

    创建RMAN删除脚本

    vim delete_rman.dat
    

    键入以下内容:

    ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE disk;
    run{
     allocate channel d1 device type disk;
     allocate channel d2 device type disk;
     delete obsolete recovery window of 7days;
     release channel d1;
     release channel d2;
    }
    

    保存退出

    创建RMAN备份脚本

    vim rman_full.sh
    

    键入以下内容:
    注意修改环境变量、备份位置及tag的部分

    #!/bin/bash
     
    #设置环境变量
    ORACLE_SID=limsdb
    ORACLE_BASE=/u01/oracle
    ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
    PATH=$PATH:$ORACLE_HOME/bin
    RMAN_LOG=/u01/backup/logs/bpmdb_fullbk_`date +"%Y.%m.%d_%H.%M.%S"`.log
    export ORACLE_SID ORACLE_BASE ORACLE_HOME PATH RMAN_LOG
    
    #输出Rman备份开始时间到日志
    START_DATE=`date +"%Y-%m-%d %H:%M:%S"`
    echo Rman备份开始_当前时间: $START_DATE>$RMAN_LOG
    
    #执行Rman备份
    #su - oraps -c"
    rman target / msglog=$RMAN_LOG append< 
    run {
    allocate channel ch00 type disk;
    allocate channel ch01 type disk;
    crosscheck archivelog all;
    delete noprompt expired archivelog all;
    backup incremental level=0 database format='/u01/backup/rman/orcl_incr0_%T_%t_%U'tag='lims_lev0';
    sql'alter system archive log current';
    backup archivelog all tag='lims_arc_bak'format='/u01/backup/rman/orcl_arch_%T_%t_%U'delete input;
    backup current controlfile tag='lims_ctlfile'format='/u01/backup/rman/ctl_file_%T_%t_%U';
    backup spfile tag='lims_spfile'format='/u01/backup/rman/spfile_%U_%T';
    crosscheck backupset;
    delete noprompt expired backup;
    delete noprompt obsolete;
    release channel ch00;
    release channel ch01;
    }
    EOF
    
    #输出Rman备份结束时间到日志
    echo Rman备份结束_当前时间: `date +"%Y-%m-%d %H:%M:%S"`>>$RMAN_LOG
    
    #根据日志输出内容检索错误信息
    strRet=''
    strRet=`awk'/ERROR MESSAGE/'$RMAN_LOG`
    
    if [ -z"$strRet"] ;
    then
    echo SUCCESS!>>$RMAN_LOG
    exit 0 ;
    else
    echo ERROR!>>$RMAN_LOG
    exit 1 ;
    fi
    

    保存退出

    利用crontab创建定时任务

    没有crontab就安一个,在此不再赘述

    查看定时任务列表

    crontab -l
    

    编辑定时任务列表

    crontab -e
    

    键入以下内容:

    # For details see man 4 crontabs
    
    # Example of job definition:
    # .---------------- minute (0 - 59)
    # | .------------- hour (0 - 23)
    # | | .---------- day of month (1 - 31)
    # | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
    # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
    # | | | | |
    # * * * * * user-name command to be executed
    
    #backup of database
    30 0 * * * /home/oracle/rman_scripts/rman_full.sh>/dev/null 2>/home/oracle/rman_scripts/error.log
    

    END

  • 相关阅读:
    JS放在head和放在body中的区别
    模板模式(Template Pattern)
    原型模式
    Linux下的头文件搜索路径
    How to Change the Default Theme Appearance [editing with no theme]
    版本控制
    What is libacl.so.1 ?
    交叉编译器 arm-linux-gnueabi 和 arm-linux-gnueabihf 的区别
    mount --bind 的妙用
    mount的bind选项
  • 原文地址:https://www.cnblogs.com/ruicccc/p/13227675.html
Copyright © 2011-2022 走看看