Operating System - HP-UX
1833408 Members
3773 Online
110052 Solutions
New Discussion

Cron Script - Archieving and Zipping Oracle Files

 
SOLVED
Go to solution
Laurie A. Krumrey
Regular Advisor

Cron Script - Archieving and Zipping Oracle Files

Hi All,

I have this script that runs every hour which
takes archive Oracle Logs and "zips" them
every 24 hours.

Well the problem is we need to zip them more often (we had our disks fill up) so we would like this done every 5 minutes instead of every 24 hours....
however, we like to "nice" the process so that
"zipping" does not interfere with production
processing.

Also is there a way to verify that the archieving/ copying is done before I start
zipping. I don't want to zip the file before
it is done being archieved. I don't think
we should have the "find" command in the script, but I would love your help here...

Here's the current Script:

# set vars
. ~/.profile > /dev/null 2>&1
ARCHPATH=/db04/oradata/${ORACLE_SID}/arch/

# log start time
echo ------------------------------------------echo "begin."; date
echo "checking ${ARCHPATH}..."

# for each .ARC file that is older than one day, zip it!
for vlc_gzfile in `find $ARCHPATH -name '*.ARC' -mtime 1`
do

echo "gzipping ${vlc_gzfile}..."
/usr/contrib/bin/gzip ${vlc_gzfile}

done

echo "done."; date


Many many thanks for your help...
Script Challenged..Laurie
Happiness is a choice
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor
Solution

Re: Cron Script - Archieving and Zipping Oracle Files

Hi Laurie:

Several comments:

> I've done something similar before. In my script I chose to drive the collection of files to archive using 'ls -lrt' to reverse the normal order and give a descending collation or oldest modified file first. I then explicity *skipped* the first file returned, thereby always leaving the most current file on disk.

> Your use of the -mtime with 'find' is probably OK since the '-mtime' option is 24-hour based.

> You should be able to test the return value of 'gzip' to insure success. Something like:

# if [ $? -eq 0 ]
# then
#...zipped_ok...
# else
#...handle error...
# fi

I trust you find this useful [no pun intended! ;-) ].

With my regards!

...JRF...
Laurie A. Krumrey
Regular Advisor

Re: Cron Script - Archieving and Zipping Oracle Files

Could I see your script?

I don't want to use the -mtime with find since
it's 24 hour based...I want it to run every
5 minutes.

I'm not sure how the error handling would
work here.

Thanks,
laurie
Happiness is a choice
James R. Ferguson
Acclaimed Contributor

Re: Cron Script - Archieving and Zipping Oracle Files

Hi Laurie:

Take a look at the man pages for 'find'. You'll see the option '-newer'. You can create a reference file with whatever time and date you want (with 'touch') and use it to drive your 'find' if you'd like to do it that way.

...JRF...
Laurie A. Krumrey
Regular Advisor

Re: Cron Script - Archieving and Zipping Oracle Files

OK here is the new script and I will execute
this from cron every 5 minutes. Does it look
OK?

# for each .ARC file - find the oldest file and zip it!
for vlc_gzfile in `find $ARCHPATH -name '*.ARC' -ls -lrt`
do

echo "gzipping ${vlc_gzfile}..."
/usr/contrib/bin/gzip ${vlc_gzfile}

if [$? -eq 0]
then zipped_ok
else
handle_error
if

done

handle_error
echol 1>$&2 vlc_gzfile Not Zipped

echo "done."; date



Happiness is a choice
James R. Ferguson
Acclaimed Contributor

Re: Cron Script - Archieving and Zipping Oracle Files

Hi Laurie:

Here's an example of using the '-newer' option of 'find'. Suppose I want to find all files named "*.out" in the /tmp directory where the modification timestamp is older than June 1 at 1300 hours. I could write:

# touch -mt 06011300 /tmp/reffile
# find /tmp -name *.out ! -newer /tmp/reffile

I have attached the "guts" of the archive script I used to 'tar' Oracle logs. See if that helps you, choose the methodlogy you like.

With my regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Cron Script - Archieving and Zipping Oracle Files

Hi Laurie:

I'll give you another way to test if a file is quiescent. I use a perl script called fileage.pl. It returns a status of zero if the file has not been touched in the last few seconds (default 60). You would use it like this:

myfile=arch230.dbf
fileage.pl -s 120 $myfile
STAT=$?
if [ ${STAT} - eq 0 ]
then
echo "${myfile} has not been changed \c"
echo "in the last 120 seconds"
gzip ${myfile}
fi

If you invoke fileage.pl without args, it gives you a full usage message. It's a fairly handy little script fdor checking if it's safe to copy/move/compress a file.

Regards, Clay

If it ain't broke, I can fix that.
Laurie A. Krumrey
Regular Advisor

Re: Cron Script - Archieving and Zipping Oracle Files

OK Dump Question...

1. How do I tell if I have Perl installed
so I can write Perl scripts?

2. Does Cron invoke Perl scripts the same
way as regular scripts? Do I have to do
any thing special?

I only hear good things about Perl, so many
I should install this on all my servers.

Laurie
Happiness is a choice
A. Clay Stephenson
Acclaimed Contributor

Re: Cron Script - Archieving and Zipping Oracle Files

Hi Laurie,

To test whether perl is installed, simply do a 'type perl'. Perl is almost alway installed on HP boxes but the version that HP distributes is often quite old. I would obtain
the latest version (and you can get the binaries so that you don't need to compile.)
Here's the URL:
http://hpux.cs.utah.edu/hppd/hpux/Languages/perl-5.6.1/

Since you seem fairly new to UNIX, I would say
after you are reasonably proficient in the shell, I would then definitely learn perl.
If you know perl (and I shudder when I say this) there is really no need to know awk, sed,
grep, etc. since essentially anything you can do in these, you can do in perl. I'm not saying you shouldn't be able to awk but rather you could learn just perl well and not HAVE to know the others. The other good thing about perl is that it runs on WindowsXX, W2K, and NT as well. In fact, it's very easy to setup bidirectional sockets, for example, between a windows box and a unix box with just a few lines of perl.

Clay
If it ain't broke, I can fix that.