zoukankan      html  css  js  c++  java
  • del_archivelog

    #!/usr/bin/env bash                         
    # INTRO : The script for delete physical standby applied archivelog.
    #         Please set ur environment variables before use it.
    #         Please execute the script on physical standby site.
    #
    # USAGE : ./del_archivelog.sh                                                            
    #                                                                     
    # TEST  : This script has been successfully tested on these platforms:                                                                     
    #         Linux 
    #         Physical standby
    #         Oracle Database 10gR2,11gR2,Include RAC                            
    #                                                       
    # NOTE  : Please test this script in ur development environment 
    #         before attempting to run it in production.                                     
    # =================================================================================
     
    #----------------------------------------------------------------------------------
    ###setup environment variables
    export ORACLE_HOME=/oracle/app/oracle/product/11.2.0/db_1
    export ORACLE_SID=standby
    export PATH=$ORACLE_HOME/bin:$PATH
    #export ARCHIVE_DIR=+DATA/standby/archivelog
    export LOG_FILE=$HOME/scripts/logs/del_archive.log
    #----------------------------------------------------------------------------------
     
    ###determine user 
    if [ `whoami` != 'oracle' ];then
    echo "Warning: Please use oracle execute.">>$LOG_FILE
    exit 99
    fi
     
    ###define archivelog sequence will be deleted
    sqlplus -s / as sysdba << EOF > tmp.log
    set lines 100 feedback off echo off heading off;
    select thread#,max(sequence#) from v$archived_log where applied='YES' group by thread# order by thread#;
    EOF
     
    MAXLINE=`cat tmp.log|wc -l`
     
    for (( i=1;i<$MAXLINE;i++ )); do
     
    i=$(( i + 1 ))
    THREAD=`sed -n "$i,$i"p tmp.log|awk -F' ' '{print $1}'`
    MAXSEQ=`sed -n "$i,$i"p tmp.log|awk -F' ' '{print $2}'`
     
    ###Retains the most recent five Archive
    MAXSEQ=$(( $MAXSEQ - 5 ))
     
    ###Delete physical standby applied archivelog
    echo "****************************************************************************" >> $LOG_FILE
    echo ">>> Begin deleting applied archivelogs : `date` <<<">>$LOG_FILE
     
    i=$(( i - 1 ))
     
    rman target / <<EOF >> $LOG_FILE
    ##catalog start with '$ARCHIVE_DIR' noprompt;
    delete noprompt archivelog until sequence $MAXSEQ thread $THREAD;
    EOF
     
    echo >> $LOG_FILE
    echo ">>> End delete applied archivelogs : `date` <<<">>$LOG_FILE
     
    echo "****************************************************************************" >> $LOG_FILE
    echo >> $LOG_FILE
     
    done
     
    rm -f tmp.log
  • 相关阅读:
    【转】winrar命令行详解
    【转】关于色彩空间sRGB和Adobe RGB...
    深入解读TPC-C指标
    解决因 RsFX devicer 而无法卸载 SQL Server 的问题
    LUHN算法
    信用卡卡号编排的含义
    关于第三方API调用的工具 WebApiClient.JIT 的使用记录
    ocelot.json模板
    C#进阶之事件与委托(Event&Delegate)
    C#进阶之面向对象(OOP)
  • 原文地址:https://www.cnblogs.com/liang545621/p/9410577.html
Copyright © 2011-2022 走看看