Save disk space by rotating older log files
When it comes to the files taking up space on your server, they fall into two general categories:
- Constant files (Linux OS, control panel). These files don't change much in size over time.
- Variable files (websites, email, logs). These files can vary widely in size as time goes by.
Website code is completely under your control, depending on what you post, and email can be deleted off your server as you see fit. Therefore, this will focus on the third variable file area: log files. Logs can grow to be quite large, especially if there is an errant process throwing tons of error messages, and theoretically large enough log files could fill up all the available disk space on your VPS. (Note: I have yet to see this actually happen, but it's definitely possible!)
The main file controlling log rotation is /etc/logrotate.conf. Default settings will rotate all files weekly (as <file>.1, <file>.2, and so on), and keep up to 4 backup files (deleting the oldest in order). One setting you should definitely change is to enable compression:
- Edit /etc/logrotate.conf
- Uncomment the '#compress' line by removing the '#' from the beginning of the line, and save the file.
Additional log rotation control files for different services are found under /etc/logrotate.d/, and named by service. For instance, in /etc/logrotate.d/exim, you will find one section for each exim logfile (exim_mainlog, exim_paniclog, and exim_rejectlog). Each of these files can contain options that will override the equivalent option in logrotate.conf; for instance, if you find that you need to rotate the exim logs daily instead of weekly because of huge spam volumes.
For more options and information, see the man page for the logrotate daemon itself:
-bash-3.00# man logrotate