Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Archive Logs Growing to Fast

RE: Archive Logs Growing to Fast

From: Afanassiev, Alex <Alex.Afanassiev_at_team.telstra.com>
Date: Wed, 22 Nov 2000 13:54:40 +1100
Message-Id: <10687.122683@fatcity.com>


This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible.

------_=_NextPart_000_01C0542F.93CA0DA4
Content-Type: text/plain

Hi Larry

Here are couple examples

 <<cleandir.sh>> <<dbarccln.sh>>

With regards
Alex Afanassiev
Oracle DBA, TOC OPS/Internet.Operations

Tel:	(03) 8 661 20 61
Fax:	(03) 9 650 36 74



> -----Original Message-----
> From: Larry Taylor [SMTP:ltaylor_at_iq.com]
> Sent: Wednesday, November 22, 2000 12:18 PM
> To: Multiple recipients of list ORACLE-L
> Subject: Archive Logs Growing to Fast
>
> Hi All,
>
> I need a script that will delete (rm) a file(s) if the file(s) is 3 days
> old.
> My archive logs are filling up my disk at a rapid pace.
>
> Does anyone have any suggestions?
>
> This is what the files look like:
>
> -rw-r----- 1 oracle dba 209715712 Nov 19 19:27 0000097621.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 19:38 0000097622.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 19:48 0000097623.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 19:59 0000097624.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 20:10 0000097625.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 20:20 0000097626.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 20:31 0000097627.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 20:42 0000097628.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 20:53 0000097629.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 21:04 0000097630.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 21:15 0000097631.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 21:26 0000097632.arc
> -rw-r----- 1 oracle dba 209715712 Nov 19 21:38 0000097633.arc
>
>
> Thanks in advance
>
> larry
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author: Larry Taylor
> INET: ltaylor_at_iq.com
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).

------_=_NextPart_000_01C0542F.93CA0DA4
Content-Type: application/octet-stream;

        name="cleandir.sh"
Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment;

        filename="cleandir.sh"

#! /bin/ksh
# name		cleandir.sh   =20
#
#		******    ATT!!! *****
# 		This scipt deletes files from the directory passed in  =09
#		as a parameter
#
# purpose	this script finds the files that has not been accessed
#               more than N days and removes them
#
# usage		cleandir.sh <dir> <days>=20
#
# parameters	$1=3Ddirectory to check (mandatory)
#		$2=3Dretention period in days (optional, defalted to 14)
#
# ..............................................................
# return code

SUCCESS=3D0
WARNING=3D1
ERROR=3D2
NOTFOUND=3D-1
#
# booleans
#

TRUE=3D0
FALSE=3D1
#
# Delete directory
DELETE=3D/tmp
#
OWNER=3Doracle
# validate parameters
#
# job name=20

JOBNAME=3D"$0"
JOBNAME_SHORT=3D`basename $JOBNAME`
ERRMSG=3D"
   $JOBNAME_SHORT: invalid parameter:
   $JOBNAME_SHORT <dir> <day>
"
if [ "$1" ];then=20

   CHECKDIR=3D$1
else=20

   echo $ERRMSG
   exit ${ERROR}
fi
if [ "$2" ]; then=20

   RTIME=3D$2
else

   RTIME=3D14
fi

# add 3 days cool off period
#if [ $RTIME -lt 3 ]; then
#   echo "$JOBNAME_SHORT: Cannot remove file(s) modified less than"
#   echo "$JOBNAME_SHORT:    $RTIME days ago. Aborting.."
#   exit ${ERROR}
#fi

if [ ! -s $CHECKDIR ]; then

   echo "$JOBNAME_SHORT: Cannot find $CHECKDIR directory. Aborting.."    exit ${ERROR}
else
# add directory filter=20

   ADMIN=3D/ora/admin
   TOOLS=3D/ora/admin/maint
   MONITOR=3D/ora/admin/monitor
   DATA1=3D/ora/data/da001
   DATA2=3D/ora/data/da002
   #ARCHIVE=3D/ora/archive
   if [ "${ORACLE_HOME}" =3D "" ]; then

      ORACLE_HOME=3D/ora/product/v7343
   fi
   if [ `echo $CHECKDIR |grep -c $ORACLE_HOME` -gt 0 -o "${CHECKDIR}" = =3D "${ADMIN}" -o "${CHECKDIR}" =3D "${TOOLS}" -o "${CHECKDIR}" =3D = "${MAINT}" -o "${CHECKDIR}" =3D "${MONITOR}" -o "${CHECKDIR}" =3D = "${DATA1}" -o "${CHECKDIR}" =3D "${DATA2}" ]; then=20

      echo "$JOBNAME_SHORT: Cannot delete files from $CHECKDIR = directory. Aborting.."

      exit ${ERROR}
fi
# Remove all files that have hnot been accessed or modified=20 # more than RTIME dats
RET=3D${NOTFOUND}
for FILE in `find ${CHECKDIR} ! -type d ! -type l -mtime +${RTIME} = -user $OWNER 2>/dev/null`; do=20

   if [ -s ${FILE} -a ${FILE} -a ${FILE} !=3D "*" -a ${FILE} !=3D "" -a = `echo "${FILE}" | grep -c "*"` -eq 0 ]; then

          #echo "${JOBNAME_SHORT}: Moving  $FILE file to"
          #echo "${JOBNAME_SHORT}:   $DELETE directory..."
          #mv $FILE $DELETE=20
          echo "${JOBNAME_SHORT}: Removing  $FILE ..."
          rm $FILE=20
          if [ $? -ne 0 ]; then
             echo "${JOBNAME_SHORT}: WARNING: Failed to remove ${FILE}"
             RET=3D${WARNING}
          else
             RET=3D${SUCCESS}
          fi
       fi

   done
fi
case ${RET} in

   $SUCCESS)

       echo "${JOBNAME_SHORT}: Completed succesfully!"
       break;;
   $WARNING)
       echo "${JOBNAME_SHORT}: Completed with warning!"
       break;;
   $NOTFOUND)
       echo "${JOBNAME_SHORT}: No files last modified more than $RTIME =
days"
       echo "${JOBNAME_SHORT}:    found in ${CHECKDIR} directory!"
       break;;

   *) ;;
esac
exit $RET =09

------_=_NextPart_000_01C0542F.93CA0DA4
Content-Type: application/octet-stream;

        name="dbarccln.sh"
Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment;

        filename="dbarccln.sh"

#! /bin/ksh
# name		dbarccln.sh   =20
#
# purpose	Check space in /ora/archive direcrory and clean it ( move to=20
#               another location and compress ) if it reached the limit =

#
# usage		dbarccln=20
#
# parameters	none=20
# ..............................................................
# booleans
TRUE=3D0
FALSE=3D1
# return code
SUCCESS=3D0
WARNING=3D1
ERROR=3D2
#
# job name=20
JOB=3D`basename $0`
TOOLS=3D/ora/admin/bin =20
BACKUPDIR=3D/orabackup =20
DONEDIR=3D/da001/ontape=20

ARC=3D/ora/archive
ULIMIT=3D70
LLIMIT=3D50
#ULIMIT=3D7
#LLIMIT=3D5
ARCHIVE_KEEP=3D1
BACKUP_KEEP=3D2
DONE_KEEP=3D2
PATH=3D/usr/bin:$HOME/bin:/opt/bin:/usr/ccs/bin:/usr/local/bin:/usr/sbin= :/usr/ucb
# check if the program is already running if [ `ps -ef | grep -c ${JOB}` -gt 3 ]; then

   echo "$JOB: `date '+%H:%M:%S'` ${JOB} is already running. Exiting = ..."

   exit $ERROR
fi
# Check if any archive destanation reached the limit print -n "$JOB: `date '+%H:%M:%S'` Getting used space in $ARC ... " CAPACITY=3D`df -k $ARC 2>/dev/null | tail -1 | awk '{print $5}'| cut -d = "%" -f1`
print ${CAPACITY}%
if [ ${CAPACITY} -lt ${ULIMIT} ]; then

   echo "$JOB: `date '+%H:%M:%S'` ${ARC} has not reached the limit = (${ULIMIT}%)."
   echo "$JOB: `date '+%H:%M:%S'` Exiting now ..."    exit $SUCCESS
fi
# check directories
if [ ! -s ${BACKUPDIR} ]; then

   echo "$JOB: `date '+%H:%M:%S'` ERROR: Cannot find ${BACKUPDIR} = directory."=20

   echo "$JOB: `date '+%H:%M:%S'` ERROR: Aborting.."    exit ${ERROR}
fi
if [ ! -s ${DONEDIR} ]; then

   echo "$JOB: `date '+%H:%M:%S'` ERROR: Cannot find ${DONEDIR} = directory."=20

   echo "$JOB: `date '+%H:%M:%S'` ERROR: Aborting.."    exit ${ERROR}
fi
# Logs=20
LOGS=3D${TOOLS}/LOGS
if [ ! -s $LOGS ]; then

   mkdir $LOGS
   if [ $? -ne 0 ]; then

      echo "$JOB: `date '+%H:%M:%S'` ERROR: Failed to create ${LOG} = directory."

      echo "$JOB: `date '+%H:%M:%S'` ERROR:   Aborting..."
      exit ${ERROR}

   fi
fi
#
# local variables
if [ "${UTILSLOG}" =3D "" ]; then

   UTILSLOG=3D"$LOGS/${JOB}_`date '+%y%m%d'`.log" fi
echo "$JOB: `date '+%H:%M:%S'` Output is redirected to " echo "$JOB: `date '+%H:%M:%S'` to ${UTILSLOG}" #
BACKUP_ARC=3D"$BACKUPDIR/`basename $JOB .sh`_`date '+%y%m%d'`.tar" PREFIX=3D1
while [ -s ${BACKUP_ARC} -o -s ${BACKUP_ARC}.Z ] do

   PREFIX=3D`expr $PREFIX + 1`
   BACKUP_ARC=3D"$BACKUPDIR/${ORACLE_SID}_arc_`date = '+%y%m%d'_${PREFIX}`.tar"
done

IN=3D$FALSE
echo "$JOB: `date '+%H:%M:%S'` Removing files from $DONEDIR" echo "$JOB: `date '+%H:%M:%S'` that have not been modified" print -n "$JOB: `date '+%H:%M:%S'` for the last ${DONE_KEEP} day(s) = ... "
# Cleanup DONE location =20
for FILE in `find ${DONEDIR}/* -mtime +${DONE_KEEP} 2>/dev/null`; do

    if [ ${IN} -eq ${FALSE} ]; then

       print=20
       IN=3D$TRUE

    fi
    if [ -s ${FILE} -a "${FILE}" !=3D "*" -a "${FILE}" !=3D "" -a `echo = "${FILE}" | grep -c "*"` -eq 0 ]; then
       print -n  "$JOB: `date '+%H:%M:%S'` $FILE ..."
       rm ${FILE}
       if [ $? -ne 0 ]; then
          print "Failed"=20
       else
          print "OK"=20
       fi

    fi
done
if [ ${IN} -eq ${FALSE} ]; then

   print "No fileS found"=20
fi
# Cleanup BACKUP destination=20
IN=3D$FALSE

echo "$JOB: `date '+%H:%M:%S'` Moving files from $BACKUPDIR that have"
echo "$JOB: `date '+%H:%M:%S'` not been modified for the last "
echo "$JOB: `date '+%H:%M:%S'` for the last ${BACKUP_KEEP} day(s)"
print -n "$JOB: `date '+%H:%M:%S'` into ${DONEDIR} ... " for FILE in `find ${BACKUPDIR}/* -mtime +${BACKUP_KEEP} 2>/dev/null`; = do

    if [ ${IN} -eq ${FALSE} ]; then

       print=20
       IN=3D$TRUE

    fi
    if [ -s ${FILE} -a "${FILE}" !=3D "*" -a "${FILE}" !=3D "" -a `echo = "${FILE}" | grep -c "*"` -eq 0 ]; then
       print -n "$JOB: `date '+%H:%M:%S'` ${FILE} ... "
       mv $FILE ${DONEDIR}
       if [ $? -ne 0 ]; then
          print "Failed"=20
       else
          print "OK"=20
       fi

    fi
done
if [ ${IN} -eq ${FALSE} ]; then

   print "No files found"=20
fi
IN=3D$FALSE

echo "$JOB: `date '+%H:%M:%S'` Compessing ${ARC} files"
echo "$JOB: `date '+%H:%M:%S'` that have not been modified "
echo "$JOB: `date '+%H:%M:%S'` for the last ${ARCHIVE_KEEP} day(s)"
print -n "$JOB: `date '+%H:%M:%S'` and moving to $BACKUPDIR" for FILE in `find ${ARC}/* -mtime +${ARCHIVE_KEEP} ! -name \*.Z ! -type = d 2>/dev/null`; do

    if [ ${IN} -eq ${FALSE} ]; then

       print=20
       IN=3D$TRUE

    fi
    print -n "$JOB: `date '+%H:%M:%S'` Compressing $FILE ... "     compress -f $FILE
    if [ $? -ne 0 ]; then

       print "Failed"
    else

       print "OK"
    fi
    b_name=3D`basename ${FILE}.Z`
    d_name=3D`dirname ${FILE}.Z`
    print -n "$JOB: `date '+%H:%M:%S'` Adding to the tar file ... "     if [ ! -f ${BACKUP_ARC} ]; then

       tar cvf ${BACKUP_ARC} -C ${d_name} ./${b_name} >> ${UTILSLOG}     else

       tar uvf ${BACKUP_ARC} -C ${d_name} ./${b_name} >> ${UTILSLOG}     fi
    if [ $? -ne 0 ]; then

       print "Failed"
    else

       print "OK"
       print -n  "$JOB: `date '+%H:%M:%S'` Moving to ${DONEDIR} ... "
       mv ${FILE}.Z ${DONEDIR}
       if [ $? -ne 0 ]; then
          print "Failed"
       else
          print "OK"
          NEWNAME=3D${DONEDIR}/`basename ${FILE}.Z`
          print -n  "$JOB: `date '+%H:%M:%S'` Touching ${NEWNAME} ... "
          touch ${NEWNAME}
          if [ $? -ne 0 ]; then
              print "Failed"
          else
              print "OK"
          fi
       fi
Received on Tue Nov 21 2000 - 20:54:40 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US