LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-11-2010, 12:05 AM   #1
fizeelinux
Member
 
Registered: Nov 2008
Posts: 91

Rep: Reputation: 15
Logrotate - Purpose of rotate and postrotate


Hi friends,

Thanks for helping me so far in this forum .I have been trying out in learning with logrotate command and logrotate configuration file )logrotate.conf

custom logfile for an process is 'test.log'

Code:
#cat /etc/logrotate.d/test
/var/log/test.log {
rotate 4
create 0600 root root
compress
dateext
size 100M
postrotate
/bin/kill -HUP 'cat /var/run/syslogd.pid 2> /dev/null 2> /dev/null || true
endscript
}
As far as to my knowledge i can understand the above ,whenever the log file (test.log) exceeds 100M a new file will be created with the file name as test.'date'.'gz'(new file is created with a current date and in a compressed format of gz) and also with permission mentioned above). I really dont know what is the role of rotate( will this be carried on only for next 4times i mean upto 400MB; (4times*file reaches 100MB)? and also what could be the purpose of postrotate?Can anyone please clarify me on this?.I knew its basic but still i am trying to have a good understanding on this with help of you friends. Thanks in advance..

Last edited by fizeelinux; 07-11-2010 at 12:06 AM.
 
Old 07-11-2010, 12:09 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,808

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
man logrotate

Code:
       rotate count
              Log  files  are  rotated  count times before being removed or mailed to the address
              specified in a mail directive. If count is 0, old versions are removed rather  than
              rotated.

       postrotate/endscript
              The lines between postrotate and endscript (both of which must appear on  lines  by
              themselves)  are  executed after the log file is rotated. These directives may only
              appear inside a log file definition.  See also prerotate.
 
Old 07-11-2010, 03:13 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
FYI: Please note that your script seems to contain errors (just a single quote somewhere)

You can use e.g. a prerotate to stop an application so it no longer writes to the log file. Next you can use a postrotate to start the application again after the log file has been rotated. That way you don't have the risk of 'corrupted' log files (the first half of a line in the rotated file, the other half in the new log file) or an application that can no longer write to the log as it has been moved (from experience, apache comes to mind for the latter).
 
Old 07-12-2010, 09:06 AM   #4
fizeelinux
Member
 
Registered: Nov 2008
Posts: 91

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Wim Sturkenboom View Post
FYI: Please note that your script seems to contain errors (just a single quote somewhere)

You can use e.g. a prerotate to stop an application so it no longer writes to the log file. Next you can use a postrotate to start the application again after the log file has been rotated. That way you don't have the risk of 'corrupted' log files (the first half of a line in the rotated file, the other half in the new log file) or an application that can no longer write to the log as it has been moved (from experience, apache comes to mind for the latter).
Thanks Wim and Alucard.Let me go through prerotate.BTW if i am not wrong as sticking on 'man rotate' description when the file test.log file exceeds 100MB it will be compressed and labeled with date on the first rotate.similarly for another 3times.so once after 4th rotation all the files will be removed.Is that make sense friends?Please let me know also i saw some examples instead of mentioning 'size', age parameter like 'daily' 'weekly' etc are mentioned in process file say 'test' so in that case will 'rotate 4' means 4 weeks ?(depending on the age or size we specify ,does rotate take the role as count or week ,daily ?etc).I may be too novice in asking this but please let me know. Thanks
 
Old 07-13-2010, 01:56 AM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
rotate 4 means that 4 unique backups will be made after which the oldest backup will disappear; this is regardless of the condition that is set

starting with no backups, the following is what will basically happen if count equals 4
Code:
1st rotate:
  mv test.log test.log.1
2nd rotate:
  mv test.log.1 test.log.2
  mv test.log test.log.1
3rd rotate:
  mv test.log.2 test.log.3
  mv test.log.1 test.log.2
  mv test.log test.log.1
4th rotate:
  mv test.log.3 test.log.4    // from here onwards, test.log.4 will contain the oldest backup
  mv test.log.2 test.log.3
  mv test.log.1 test.log.2
  mv test.log test.log.1
5th (and higher) rotate:
  mv test.log.3 test.log.4
  mv test.log.2 test.log.3
  mv test.log.1 test.log.2
  mv test.log test.log.1
From the above, you can see that you will always have 4 backups (after a while). If you use weekly/daily, it will indeed imply 4 weeks/days of backups

Code:
rotate count
    Log files are rotated <count> times before being removed or mailed to the address specified  in  a  mail
    directive. If count is 0, old versions are removed rather then rotated.

Last edited by Wim Sturkenboom; 07-13-2010 at 02:00 AM. Reason: fixed mistake
 
Old 07-14-2010, 05:00 AM   #6
fizeelinux
Member
 
Registered: Nov 2008
Posts: 91

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by Wim Sturkenboom View Post
rotate 4 means that 4 unique backups will be made after which the oldest backup will disappear; this is regardless of the condition that is set

starting with no backups, the following is what will basically happen if count equals 4
Code:
1st rotate:
  mv test.log test.log.1
2nd rotate:
  mv test.log.1 test.log.2
  mv test.log test.log.1
3rd rotate:
  mv test.log.2 test.log.3
  mv test.log.1 test.log.2
  mv test.log test.log.1
4th rotate:
  mv test.log.3 test.log.4    // from here onwards, test.log.4 will contain the oldest backup
  mv test.log.2 test.log.3
  mv test.log.1 test.log.2
  mv test.log test.log.1
5th (and higher) rotate:
  mv test.log.3 test.log.4
  mv test.log.2 test.log.3
  mv test.log.1 test.log.2
  mv test.log test.log.1
From the above, you can see that you will always have 4 backups (after a while). If you use weekly/daily, it will indeed imply 4 weeks/days of backups

Code:
rotate count
    Log files are rotated <count> times before being removed or mailed to the address specified  in  a  mail
    directive. If count is 0, old versions are removed rather then rotated.
Thank you so much for the detailed explanation Wim.

Last edited by fizeelinux; 07-14-2010 at 05:01 AM. Reason: Grammar mistake
 
  


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
lastlog - What is it, and how do I rotate it? ifm Linux - Newbie 9 04-22-2011 10:45 AM
rotate framebuffer Jurrian Linux - Embedded & Single-board computer 1 04-13-2009 02:48 PM
Rotate display -- Option "Rotate" "CCW" Brad.Scalio@noaa.gov Linux - General 0 01-27-2009 06:32 AM
rotate text bizshop Linux - Software 1 06-22-2005 06:17 PM
how do I rotate the syslog jonsag Linux - Newbie 3 12-19-2004 03:33 PM


All times are GMT -5. The time now is 04:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration