????????DEV???UAT????????Щ???????????????鵵??????????????????????????archive?鵵???????????????′????????????á????????????Σ???????????shell????????????????Щ?鵵??????????????????鵵?????????

????1??????鵵???shell???

robin@SZDB:~/dba_scripts/custom/bin> more remove_arch_dump.sh
#!/bin/bash
# ------------------------------------------------------------+
#   FileName: remove_arch_dump.sh                             |
#   Desc:                                                     |
#        Remove old archived log and data pump file           |
#   Usage:                                                    |
#        ./remove_arch_dump.sh                                |
#                                                             |
#   Authror : Robinson                                        |
#   Blog    :http://blog.csdn.net/robinson_0612              |
# ------------------------------------------------------------+

filename=/etc/oratab

cat $filename | while read LINE
do
    case $LINE in
        #*)                ;;        #comment-line in oratab
        *)
        ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`
        echo $ORACLE_SID
 
        # ---------------------------------
        # define archived log directory   
        # ---------------------------------
        dir=/u02/database/$ORACLE_SID/archive/
        echo $dir

        filelist=`ls -t $dir`
        echo $filelist
      
        # ----------------------------------------------------------
        # start to remove archived log and keep last 2 archived log
        # ----------------------------------------------------------
        count=0
        for filename in $filelist
        do
                echo $filename
                count=$(($count+1))
                if [ $count -gt 2 ]; then
                        echo $count
                        rm -vrf $dir$filename
                fi
        done
        ls -tr $dir
      
        # --------------------------------
        # define data pump dump directory
        # --------------------------------
        dir=/u02/database/$ORACLE_SID/BNR/dump/
        echo $dir

        filelist=`ls -t $dir`
        echo $filelist
      
        # ---------------------------------------------------------
        # start to remove data pump file and keep last 5 dump file
        # ---------------------------------------------------------
        count=0
        for filename in $filelist
        do
                echo $filename
                count=$(($count+1))
                if [ $count -gt 5 ]; then
                        echo $count
                        rm -vrf $dir$filename
                fi
        done
        ls -tr $dir

     ;;
    esac
done
exit

????2????????

????a???y??????????????????oratab?ж??????????SID?????????????鵵???·?????datapump dump·????

????b??????????for?????????鵵????????????2???鵵????????

????c???????????????for???????????????SID??????dump(Oracle datapump)???μ?????dump?????

????d???????鵵?????????趨?????dump??????5??????????????????????(dump??5??????鵵???2)????????

????e?????????????dump·?????????dump?????????

????f???????????????crontab??