1821639 Members
3019 Online
109633 Solutions
New Discussion юеВ

Deleteing archive files

 
SOLVED
Go to solution
Gops_1
Regular Advisor

Deleteing archive files

I have filled with lots archive files in the directory /u01/archives

It is increasing every day. But i need to write a bash/perl script and put it in crot tab. The logic is

To check the disk utilization of /u01/archives if it exceeds 80%, then delete the archive files.

Does anyone has this in your environment. How do you manage archive files ? Please share your automation in your env. plz...

Points Points....

Thanks
gV
6 REPLIES 6
Sharma Sanjeev
Respected Contributor
Solution

Re: Deleteing archive files

Hi Gops

You can add enrty in Cron which will find files on this FS which will clear/Zip the logs for some time old say 30 days

Entry in Cron

15 00 * * * /usr/bin/find /u01/archives -type f -mtime +30 -exec /usr/bin/compress {} \;
it will compress files

to delete tham

30 00 * * * /usr/bin/find /u01/archives -type f -mtime +90 -exec /usr/bin/rm {} \;

Regards
Sanjeev
Everything is Possible as " IMPOSSIBLE" word itself says I M POSSIBLE
Deepak Kr
Respected Contributor

Re: Deleteing archive files

Hi,

You can start with utilisation check


bdf /u01/archives |grep "80%"
if [$i==0]

find files to be deleted
remove files

"There is always some scope for improvement"
Deepak Kr
Respected Contributor

Re: Deleteing archive files

Also provide cron requirements so that we can help you!!

Crontab syntax :-

A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.

* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

"There is always some scope for improvement"
Rasheed Tamton
Honored Contributor

Re: Deleteing archive files

>To check the disk utilization of /u01/archives if it exceeds 80%, then delete the archive files.

If you put on cron on a daily/hourly basis, this might help.

while bdf /u01/archives |grep '8[0-9]%'
do
ls $(ls -1rt /u01/archives/*|head -1)
exit
done


>ls $(ls -1rt /u01/archives/*|head -1)

-replace the first ls with rm to remove
-head -1 is taking the oldest file from the sorted by date list.
increase the number for the number of files you want to remove as per your requirement. You have to make the cron either hourly or daily/weekly as per your data growth.

Regards.
Gokul Chandola
Trusted Contributor

Re: Deleteing archive files

Hi,
Please read the following document, may be usefull...

http://docs.hp.com/en/5991-0662/5991-0662.pdf

├в Task 1: Backing Up Your Data Files├в

├в Task 2: Creating an Operating System Recovery Archive├в


Regards,
Gokul Chandola
There is always some scope for improvment.
Dennis Handly
Acclaimed Contributor

Re: Deleteing archive files

>if it exceeds 80%, then delete the archive files.

Delete all? Or only older ones until below X%?

>Sanjeev: 15 00 * * * /usr/bin/find /u01/archives -type f -mtime +30 -exec /usr/bin/compress {} \;

You can improve it by using gzip and skipping files that were gzipped:
find /u01/archives -type f ! name "*.gz" -mtime +30 -exec gzip {} +

And speed up the rm:
find /u01/archives -type f -mtime +90 -exec rm -f {} +

Checking if > 80%:
if [ $(bdf /u01/archives | awk '/% / {print $(NF-1)+0}') -gt 80 ]; then
echo "greater than 80"
fi