Now on ScienceBlogs: The Lights Stay On Inside a Black Hole!

Seed Media Group

Collective Imagination

Greg Laden's Blog

Evolution, Life Sciences, Science Education, Human Evolution, and Stuff

Recent Comments

Profile


Welcome to Greg Laden's Blog.




Nature Blog Network



Search

Join the best atheist themed blogroll!

Archives

Recent Posts

« Some great Sunday reading. | Main | Today's Sunday Bible Reading Ezekiel 25:17 »

How to keep your server's hard drive from filling up with log files.

Category: Computer TricksLinuxOpenSource
Posted on: October 25, 2009 12:11 PM, by Greg Laden

Log files are good because they log stuff, so you can find out what's been going on and troubleshoot. But they tend to accumulate and can actually fill up your hard drive. Most Linux distros have automatic log file management for common system logs, but if you are running something on your server that keeps a log not thusly covered, you may have to manage that log file by yourself.

You could have a cron entry that simply deletes the log files in question every week or so, but then you lose the benefits of having a log file to begin with. The usual solution to this is called "Log Rotation" and it works like this:

The usual solution to the space problem is to rotate your log files. (We'll see an unusual solution later in this section.) After a specific duration has passed or a file size has been reached, the current log file is moved to another name, e.g., logfile.0. The logging process is then continued into an empty file. At the next interval or limit, we repeat the process, first moving the backup file (logfile.0 ) to another name (like logfile.1). This process is repeated until a set number backup files have been created. The oldest backup file at that point is deleted.

There's a script or two here to make this work. Here's another script (scroll down to see it), and here's a bash script that uses cron to rotate log files.

Share this: Stumbleupon Reddit Email + More

TrackBacks

TrackBack URL for this entry: http://scienceblogs.com/mt/pings/123186

Comments

1

Why not just use logrotate? (http://www.linuxconfig.org/Logrotate)

Easy to manage different schedules for different logs, run commands before or after (e.g. to make an application reopen its logfiles)

Posted by: Jonathan | October 25, 2009 4:36 PM

2

As an addendum to the previous comment, this is what most distros use to manage their own logs (as you elude to in the post), but the rules for it are really not hard to write, probably easier than an adhoc script.

Posted by: Jonathan | October 25, 2009 4:39 PM

Post a Comment

(Email is required for authentication purposes only. On some blogs, comments are moderated for spam, so your comment may not appear immediately.)





ScienceBlogs

Search ScienceBlogs:

Go to:

Advertisement
Enter to win a free copy of The Monty Hall Problem
Visit the Collective Imagination blog
Advertisement
Collective Imagination

© 2006-2009 Seed Media Group LLC. ScienceBlogs is a registered trademark of Seed Media Group. All rights reserved.

Sites by Seed Media Group: Seed Media Group | ScienceBlogs | SEEDMAGAZINE.COM