Operating System - HP-UX
1819681 Members
3756 Online
109605 Solutions
New Discussion юеВ

create a script to delete old Oracle archive log files

 
SOLVED
Go to solution
Yvette Johnson
Advisor

create a script to delete old Oracle archive log files

Howdy! I need assistance with creating a script to delete old log files. Oracle creates archive log files. I want to keep files for at least 14 days and delete older files.

Thanks in advance for your help!!
17 REPLIES 17
Uday_S_Ankolekar
Honored Contributor
Solution

Re: create a script to delete old Oracle archive log files

You can run this one liner as a cronjob every day..

find dirname -type f -mtime +14 -exec rm {} \;

-USA..
Good Luck..
Yvette Johnson
Advisor

Re: create a script to delete old Oracle archive log files

Thanks for you help!
Yvette Johnson
Advisor

Re: create a script to delete old Oracle archive log files

I typed
find prod*.arc -type f -mtime +14 -exec rm{}\;

Results: find: -exec not terminated with ';'

What did I do wrong?
Pete Randall
Outstanding Contributor

Re: create a script to delete old Oracle archive log files

You need a space between the } and the \.


Pete

Pete
Yvette Johnson
Advisor

Re: create a script to delete old Oracle archive log files

I typed:
find prod*.arc -type f -mtime +14 -exec rm{ } \;

Results: Missing }.
Pete Randall
Outstanding Contributor

Re: create a script to delete old Oracle archive log files

I would also suggest that you use a full path name for the directory. You will probably want to run this from cron and cron has a pretty minimal environment so full path names are a necessity, even to the point of specifying /usr/bin/find rather than just find.


Pete

Pete
Yvette Johnson
Advisor

Re: create a script to delete old Oracle archive log files

I received this message from crontab when saving the file:

31 14 find /testing1/arch-prod/prod*.arc -type f -mtime +14 -exec rm{ } \;
crontab: error on previous line; unexpected character found in line.
Pete Randall
Outstanding Contributor

Re: create a script to delete old Oracle archive log files

Try
find /testing1/arch-prod -name 'prod*.arc' -type f -mtime +14 -exec rm{ } \;

instead.


Pete

Pete
Pete Randall
Outstanding Contributor

Re: create a script to delete old Oracle archive log files

Oh, and you've also got an extra space between your curly braces - it should be {} \; - that's curlybrace curleybrace space backslash semicolon.


Pete

Pete
Yvette Johnson
Advisor

Re: create a script to delete old Oracle archive log files

I removed the space but I'm still getting the error message when saving cron.

I ran this command manually, my results were "Usage: rm [-Rfir] file ..."
Pete Randall
Outstanding Contributor

Re: create a script to delete old Oracle archive log files

find /testing1/arch-prod -name 'prod*.arc' -type f -mtime +14 -exec rm{} \;


Pete

Pete
Pete Randall
Outstanding Contributor

Re: create a script to delete old Oracle archive log files

Oops - now we're missing a space before the first curly brace - it should be:

find /testing1/arch-prod -name 'prod*.arc' -type f -mtime +14 -exec rm {} \;


Pete

Pete
Yvette Johnson
Advisor

Re: create a script to delete old Oracle archive log files

find /testing1/arch-prod/ -type f -mtime +14 -exec rm {} \;


I used this command and it works. Thanks for your help!
Pete Randall
Outstanding Contributor

Re: create a script to delete old Oracle archive log files

Yvette,

Just so you know, the way you have the command, it's going to delete every file in /testing1/arch-prod/ that's older than 14 days. If the only thing in that directory is archive log files then that's fine. If there are other files located there, you're going to want to specify exactly what you want to delete with the -name syntax that I've been showing you.

Good luck,


Pete

Pete
Yvette Johnson
Advisor

Re: create a script to delete old Oracle archive log files

The only thing in this directory is archive log files.

Again, thanks for your help!

Yvette
Hein van den Heuvel
Honored Contributor

Re: create a script to delete old Oracle archive log files

Yvette,

It is great to hear/see that the question you asked is answerred. But I can not help but wonder whether you asked the right question.

The validity / usefulness of Oracle archive logs is only indirectly a function of their age. The real decision whether you can delete an archive log is
1- whether it is moved to more permanent storage
2- whether a fresh full backup was made in teh mean time.

If your main backup is 16 days old, then you will need those archive logs from day 14 and 15 in order to be able to recover.

Conversely, if your main backup is 7 days old, then all archives older than 8 days are useless.

I hope that your archive cleaning is carefully integrated with your backup procedures!

Mind you I have never ever actually had to set this up, but if I had to, then I would probably rename my archive log directory to a date-stamped one whenever i made a new full backup, and create a fresh empty directory. And when/if I roll them out to tape/optical storage then I'd rename them into yet another 'archived' directory. In doing so the directories would tell me what can safely be deleted, not the ages of the file.

fwiw,
Hein.


Yvette Johnson
Advisor

Re: create a script to delete old Oracle archive log files

Thanks for your reply. We perform a tape back up of the archive logs. We try to keep at least 14 days on the server.