LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 12-12-2013, 10:48 AM   #1
mariogarcia
Member
 
Registered: Sep 2005
Distribution: debian, solaris 10
Posts: 202

Rep: Reputation: 31
logrotate compress files after 7 days and keep them for two months.


Hello

I have a request to rotate files daily but keep them clear text the first 7 days. after the 7 days compress them and keep them for two months..
I do not know how to do the 7 days compress bit as delaycompress only skips one logfile rotation.

this is my current config:

/var/log/esx.log
{
daily
missingok
notifempty
nocompress
` postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}

this should create a new logfile daily uncompressed but i should compress them after 7 days. any idea how to do that.

thank you

Mario
 
Old 12-12-2013, 10:55 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,289

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
not really sure what that code segment is supposed to represent (seems like it is site specific).

you probably want to use the find command to find logs that are 7 days old then compress them. e.g.:
Code:
find /whatever/floats/your/boat -type f -mtime +7 -exec tar -cvjf "{}".tar.bz2 {} \;
you probably have to take care that it doesnt reprocess the same files after another 7 days.

Last edited by schneidz; 12-12-2013 at 11:02 AM.
 
Old 12-13-2013, 03:01 AM   #3
mariogarcia
Member
 
Registered: Sep 2005
Distribution: debian, solaris 10
Posts: 202

Original Poster
Rep: Reputation: 31
it is supposed to be logratate on ubuntu.

I thought there was a possibility on logrotate to do it.

there are already compressed files on /var/log folder. a find that you suggested will compress already compressed files found there and older than 7 days..
also how about the rotation after two months.

thanks.
 
Old 12-13-2013, 08:04 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,289

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
sorry i dont have much expertise with logrotate. my brute force method above is kinda' a hack but it seems log rotate would be the better tool.

this seems related:
Code:
[schneidz@hyper ~]$ cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
	minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.
i finished reading the man page of logrotate and i think you are rite that there is no way to delay compression beyond 1 cycle.

Quote:
Originally Posted by mariogarcia View Post
...
there are already compressed files on /var/log folder. a find that you suggested will compress already compressed files found there and older than 7 days..
then you would need to exclude those using find somehow.
Quote:
Originally Posted by mariogarcia View Post
also how about the rotation after two months.

thanks.
my suggestion was really just a nudge in the rite direction.

Last edited by schneidz; 12-13-2013 at 08:26 AM.
 
Old 12-13-2013, 08:29 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,104

Rep: Reputation: 1310Reputation: 1310Reputation: 1310Reputation: 1310Reputation: 1310Reputation: 1310Reputation: 1310Reputation: 1310Reputation: 1310Reputation: 1310
Code:
man logrotate
postrotate/endscript

The lines between postrotate and endscript (both of which must appear on lines by themselves) are executed (using /bin/sh) after the log file is rotated.
So you can put commands etc. in the postrotate/endscript section to deal with your requirements. You could try something like:

Code:
postrotate
  reload rsyslog >/dev/null 2>&1 || true
  find /var/log -name "esx.log.?" -mtime +7 -exec gzip {} \;
  find /var/log -name "esx.log.*gz" -mtime +60 -delete
endscript
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Script: find, compress, remove original files, older than x days? blacklion Linux - General 5 02-27-2012 10:22 AM
This has been bugging me for days.... or months.... whichever.... styl0 Slackware 10 01-11-2010 12:03 AM
It took only 4 months and 5 days alan_ri LQ Suggestions & Feedback 4 08-05-2009 07:05 PM
Logrotate: compress logs in a temp directory gbratig AIX 3 04-12-2008 10:42 PM
How to get logrotate to only rotate files 2 days old. yoda_mon Linux - Software 1 05-18-2006 08:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 06:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration