Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a log file ircd.log in /home/irc.

I want to rotate it daily at 00:00 and keep 7 days.

I want the rotated log files to be saved as ircd.log.YYYYMMDD for example ircd.log.20140505.

Can someone please tell me the package to use and also an example configuration for it based on this? Also is it possible to store this configuration at the user level?

share|improve this question

2 Answers 2

As @bain mentioned, the package is called logrotate. To rotate this file as you have mentioned, you could use the following configuration in /etc/logrotate.d/irc:

/home/irc/ircd.log {
    daily
    rotate 7
    compress
    missingok
    create 0644 irc irc
    su irc irc
}

A breakdown of the configuration options:

  • The daily option tells logrotate to process this file every day when it is run.
  • The rotate 7 option tells it to keep 7 copies.
  • The compress option tells it to gzip the old files.
  • missingok tells logrotate not to complain if it is missing.
  • create tells the mode, owner, and group to use when creating files.
  • su changes the user who runs the compression, etc, so you may not want to include it
share|improve this answer
    
I was planning to set up logrotate for some script logs in my home folder as well. This is unrelated to the question but do you by any chance know if the compressed archives retain user permissions (seeing how logrotate is executed with root permissions)? –  Glutanimate May 7 at 13:47
1  
I've edited my post to include the su option, which I believe is what you are looking for. –  jkt123 May 7 at 17:20
    
@jkt213 Thanks! –  Glutanimate May 7 at 19:49

The package you want is called "logrotate". The man page has examples, and if you search you will find many tutorials on the web.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.