1827791 Members
2642 Online
109969 Solutions
New Discussion

Re: arhive script help.

 
Ragni Singh
Super Advisor

arhive script help.

Hello, I would like to write a script that will run in the weekly cron job to archive the prior weeks logs. This is what I did originally..

ls -l

-rw-r--r-- 1 postgres postgres 120859203 Jan 15 23:59 postgresql-2006-01-15_000000.log
-rw-r--r-- 1 postgres postgres 940274970 Jan 16 23:58 postgresql-2006-01-16_000000.log
-rw-r--r-- 1 postgres postgres 976725601 Jan 17 23:59 postgresql-2006-01-17_000000.log
-rw-r--r-- 1 postgres postgres 970093678 Jan 18 23:59 postgresql-2006-01-18_000000.log
-rw-r--r-- 1 postgres postgres 858010447 Jan 19 23:59 postgresql-2006-01-19_000000.log
-rw------- 1 postgres postgres 912979525 Jan 20 18:36 postgresql-2006-01-20_000000.log
-rw------- 1 postgres postgres 49227396 Jan 21 00:00 postgresql-2006-01-20_183708.log
-rw------- 1 postgres postgres 142989912 Jan 21 23:59 postgresql-2006-01-21_000000.log
-rw------- 1 postgres postgres 202722648 Jan 22 23:59 postgresql-2006-01-22_000000.log
-rw------- 1 postgres postgres 749064835 Jan 23 12:12 postgresql-2006-01-23_000000.log

find /var/log/pgsql/* -type f -mtime +5 gzip {} \;

Looks like this will work but it also touches the file currently in use..so now..

I only need to select the *.logs created in the last 7 days and gzip them into a single archive for the week.

MY goal here is archive everything except the file currently in use / being written to.
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: arhive script help.

Shalom,

You can actually download a tool that does it for you. Its called logrotate.

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/logrotate-2.5/

It hasn't been updated in a while but it works very nicely. Its configurable to any log name or location.

Just like Linux.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Stuart Browne
Honored Contributor

Re: arhive script help.

So you want to gzip old .log files, not touch the existing .gz files..

find /var/log/pgsql -type f -name "*.log" -mtime +5 -exec gzip {} \;

should do it.
One long-haired git at your service...
Steven E. Protter
Exalted Contributor

Re: arhive script help.

ERR,

Thought I was posting to hpux.

logrotate is built into Linux

rpm -qa | grep logrotate

chkconfig logroate on

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Stuart Browne
Honored Contributor

Re: arhive script help.

Per-service configuration usually lives in '/etc/logrotate.d'.

But 'logrotate' is designed to do the rotation for you, but it looks like Postgre is doing that, so.. I'm not sure if you can get it to just compress the logs..

Worth looking into though ;)
One long-haired git at your service...
Ragni Singh
Super Advisor

Re: arhive script help.

I have posted a new question.