0

I am trying to figure out how logrotate work regarding disk space but not able to figure it out?

Scenario:

Let say I have 2GB of the log file and free disk space is also 2 GB, does logrotate first check do we have a sufficient disk space before rotating/compressing that file

In this scenario is it going to fail as it needs 2GB of space?

              OR

logrotate going to compress this file let say ~400MB as it thinks it already has sufficient space?

Stefan Lasiewski
  • 23,667
  • 41
  • 132
  • 186
Prashant Lakhera
  • 713
  • 2
  • 10
  • 25
  • Ultimately, if log files are growing so big you're risking not being able to rotate them, you need either more frequent rotations or a bigger disk. Trying to micro-optimize your disk space like this will end in tears some day. – ceejayoz Aug 06 '18 at 21:31
  • Thanks, @ceejayoz I understand that part and it's just as an example, I want to find it out how logrotate actually work? Does it check any disk space before rotating log file? – Prashant Lakhera Aug 06 '18 at 21:33
  • I doubt it does. – ceejayoz Aug 06 '18 at 21:34
  • 2
    @PrashantLakhera No, Logrotate by itself does not check for disk space by default, but you can do that on your own by adding a `prerotate/endscript` to check the diskspace before running the logrotate job. To see how logrotate works, check the logrotate manpage to get started, and check `/etc/logrotate.d` for some examples. If you find a solution, feel free to post it below as an answer to your own question. – Stefan Lasiewski Aug 06 '18 at 22:45
  • Thanks, @StefanLasiewski yes this is a kind of unfortunate, I was wondering what is the point of log rotation in case of disk space is full or doesn't have sufficient space to rotate the file, it's just going to fail silently. I checked it via running logrotate in debug mode logrotate -d -v -f /etc/logrotate.d/testlogrot OR strace but don't find any reference to disk system call. – Prashant Lakhera Aug 06 '18 at 22:56
  • 2
    logrotate is a decent tool, but it's old and has fairly simple functionality which only does what you tell it to do. It doesn't check diskspace, and will happily fill up a disk, and try again day after day. Checking the diskspace is considered outside the scope of this tool, and some discussion can be seen here: https://bugs.launchpad.net/fuel/+bug/1591026 – Stefan Lasiewski Aug 06 '18 at 23:14

0 Answers0