Friday, July 31, 2015

Automatically Moving Archive to Backup Location

 

Linux – Shell Scripting
Automatically Moving Archive to Backup Location

Today I have been asked by one of my friend to write another script which automatically move archivelog to backup location once its going to full.  I wrote a script which periodically check (cron) every hours to check the free space in archive mount point and move to backup location if required.

#!/bin/ksh
 
printf "\n  Automatically move Archivelogs to other mountpoint once getting full ---  \n"
 
retcode=$?
 
filesize=`df -k |grep /u02 | awk '{ print $5 }'`
mname=`df -k | grep /u02 | awk '{ print $6 }'`
 
mpct=${filesize//%}
 
 
  if [ $retcode != '0' ]; then
     printf "FATAL ERROR \n"
     ERROR_FLG='1'
  else
     if [ $mpct -gt 50 ]; then
        printf "\n  Alert - Mountpoint - $mname is above 50 and  $mpct pct  - utilizezd ...\n"
 
        printf "\n  Message : Start Clearing Mount point ....... \n"
        printf "\n  Running ........... \n"
 
        mv /u02/Archive/*.arc /Backup/
 
        printf "\n  Finished ........... \n"
        newsize=`df -k |grep /u02 | awk '{ print $5 }'`
        nsize=${newsize//%}
        printf "\n Current Utilization $mname is $nsize\n"
     else
        printf "\n  Filesystem is stable and available is $mpct \n"
     fi
  fi
 

Create an entry in cron tab with periodically check every hour.

No comments:

Post a Comment