logrotate unable to rotate logs

7,328

I go out on a limp here, but the manpage states

-d, --debug
Turns on debug mode and implies -v. In debug mode, no changes will be made to the logs or to the logrotate state file. 

So logrotate doesn't do anything. It just writes out what it would do. If you want verbose output, supply -v, not -d as option.

Edit: The fact that logrotate puts out messages like

 log /var/log/testlog.16.gz doesn't exist -- won't try to dispose of it

is nothing to be concerned about. In fact, it is expected behaviour! The verbose output shows you exactly what it's doing. It tries to increment the version numbers beginning with the oldest file testlog.15.gz which doesn't exist yet. It will, once 15 rotations have been performed. It's not an error. That goes on until finally testlog.1.gz does exist and is renamed to testlog.2.gz

Since you specified

start 1 

testlog.0.gz is again not there, but nevertheless: testlog is moved to testlog.1 (without compression, because of delaycompress)

In the end it tries to dispose of the 16th log file, since

rotate 15

was given. The file is not there (again: yet), but that should not matter to either you, or the program. The directory listing shows that it did precisely what i was told. As the logs are rotated repeatedly, the "missing" files will show up and the messages will subside.

After all you are running the program in verbose mode, so you should expect output like this.

Share:
7,328

Related videos on Youtube

Sandeep Singh
Author by

Sandeep Singh

LinkedIn Profile: http://in.linkedin.com/pub/sandeep-singh/20/687/bb4 Opensource Projects on GitHub: http://github.com/sandeepsinghmails My vim Script: http://www.vim.org/scripts/script.php?script_id=4439

Updated on September 18, 2022

Comments

  • Sandeep Singh
    Sandeep Singh over 1 year

    logrotate is unable to rotate my logs. I have checked the file permissions, they are fine.

    I have even tried by putting "su root root" in the configuration file, still I am facing the same issue.

    Please find the relevant details below:

    logrotate.conf file:

    /var/log/testlog {
        compress
        delaycompress
         maxage 180
        rotate 15
        size 1024M
        start 1
        rotate 15
        missingok
    }
    

    Debug Logs: [using "-d]

    rotating pattern: /var/log/testlog  1073741824 bytes (15 rotations)
    empty log files are not rotated, old logs are removed
    considering log /var/log/testlog
      log needs rotating
    rotating log /var/log/testlog, log->rotateCount is 15
    dateext suffix '-20140708'
    glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    compressing log with: /bin/gzip
    renaming /var/log/testlog.15.gz to /var/log/testlog.16.gz (rotatecount 15, logstart 1, i 15), 
    renaming /var/log/testlog.14.gz to /var/log/testlog.15.gz (rotatecount 15, logstart 1, i 14), 
    renaming /var/log/testlog.13.gz to /var/log/testlog.14.gz (rotatecount 15, logstart 1, i 13), 
    renaming /var/log/testlog.12.gz to /var/log/testlog.13.gz (rotatecount 15, logstart 1, i 12), 
    renaming /var/log/testlog.11.gz to /var/log/testlog.12.gz (rotatecount 15, logstart 1, i 11), 
    renaming /var/log/testlog.10.gz to /var/log/testlog.11.gz (rotatecount 15, logstart 1, i 10), 
    renaming /var/log/testlog.9.gz to /var/log/testlog.10.gz (rotatecount 15, logstart 1, i 9), 
    renaming /var/log/testlog.8.gz to /var/log/testlog.9.gz (rotatecount 15, logstart 1, i 8), 
    renaming /var/log/testlog.7.gz to /var/log/testlog.8.gz (rotatecount 15, logstart 1, i 7), 
    renaming /var/log/testlog.6.gz to /var/log/testlog.7.gz (rotatecount 15, logstart 1, i 6), 
    renaming /var/log/testlog.5.gz to /var/log/testlog.6.gz (rotatecount 15, logstart 1, i 5), 
    renaming /var/log/testlog.4.gz to /var/log/testlog.5.gz (rotatecount 15, logstart 1, i 4), 
    renaming /var/log/testlog.3.gz to /var/log/testlog.4.gz (rotatecount 15, logstart 1, i 3), 
    renaming /var/log/testlog.2.gz to /var/log/testlog.3.gz (rotatecount 15, logstart 1, i 2), 
    renaming /var/log/testlog.1.gz to /var/log/testlog.2.gz (rotatecount 15, logstart 1, i 1), 
    renaming /var/log/testlog.0.gz to /var/log/testlog.1.gz (rotatecount 15, logstart 1, i 0), 
    renaming /var/log/testlog to /var/log/testlog.1
    removing old log /var/log/testlog.16.gz
    error: error opening /var/log/testlog.16.gz: No such file or directory
    

    Verbose Output:

    rotating pattern: /var/log/testlog  1073741824 bytes (15 rotations)
    empty log files are not rotated, old logs are removed
    considering log /var/log/testlog
      log needs rotating
    rotating log /var/log/testlog, log->rotateCount is 15
    dateext suffix '-20140625'
    glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    compressing log with: /bin/gzip
    renaming /var/log/testlog.15.gz to /var/log/testlog.16.gz (rotatecount 15, logstart 1, i 15), 
    old log /var/log/testlog.15.gz does not exist
    renaming /var/log/testlog.14.gz to /var/log/testlog.15.gz (rotatecount 15, logstart 1, i 14), 
    old log /var/log/testlog.14.gz does not exist
    renaming /var/log/testlog.13.gz to /var/log/testlog.14.gz (rotatecount 15, logstart 1, i 13), 
    old log /var/log/testlog.13.gz does not exist
    renaming /var/log/testlog.12.gz to /var/log/testlog.13.gz (rotatecount 15, logstart 1, i 12), 
    old log /var/log/testlog.12.gz does not exist
    renaming /var/log/testlog.11.gz to /var/log/testlog.12.gz (rotatecount 15, logstart 1, i 11), 
    old log /var/log/testlog.11.gz does not exist
    renaming /var/log/testlog.10.gz to /var/log/testlog.11.gz (rotatecount 15, logstart 1, i 10), 
    old log /var/log/testlog.10.gz does not exist
    renaming /var/log/testlog.9.gz to /var/log/testlog.10.gz (rotatecount 15, logstart 1, i 9), 
    old log /var/log/testlog.9.gz does not exist
    renaming /var/log/testlog.8.gz to /var/log/testlog.9.gz (rotatecount 15, logstart 1, i 8), 
    old log /var/log/testlog.8.gz does not exist
    renaming /var/log/testlog.7.gz to /var/log/testlog.8.gz (rotatecount 15, logstart 1, i 7), 
    old log /var/log/testlog.7.gz does not exist
    renaming /var/log/testlog.6.gz to /var/log/testlog.7.gz (rotatecount 15, logstart 1, i 6), 
    old log /var/log/testlog.6.gz does not exist
    renaming /var/log/testlog.5.gz to /var/log/testlog.6.gz (rotatecount 15, logstart 1, i 5), 
    old log /var/log/testlog.5.gz does not exist
    renaming /var/log/testlog.4.gz to /var/log/testlog.5.gz (rotatecount 15, logstart 1, i 4), 
    old log /var/log/testlog.4.gz does not exist
    renaming /var/log/testlog.3.gz to /var/log/testlog.4.gz (rotatecount 15, logstart 1, i 3), 
    old log /var/log/testlog.3.gz does not exist
    renaming /var/log/testlog.2.gz to /var/log/testlog.3.gz (rotatecount 15, logstart 1, i 2), 
    old log /var/log/testlog.2.gz does not exist
    renaming /var/log/testlog.1.gz to /var/log/testlog.2.gz (rotatecount 15, logstart 1, i 1), 
    renaming /var/log/testlog.0.gz to /var/log/testlog.1.gz (rotatecount 15, logstart 1, i 0), 
    old log /var/log/testlog.0.gz does not exist
    log /var/log/testlog.16.gz doesn't exist -- won't try to dispose of it
    renaming /var/log/testlog to /var/log/testlog.1
    

    Output of ls /var/log/testlog* :

    /var/log/testlog  
    /var/log/testlog.1  
    /var/log/testlog.2.gz
    

    Can somebody please provide me some hint to resolve this issue?

    Thanks

    • garethTheRed
      garethTheRed almost 10 years
      What distro are you using?
    • Sandeep Singh
      Sandeep Singh almost 10 years
      @garethTheRed: I am using opensuse linux 13.1
    • Toli
      Toli almost 10 years
      So there are no testlog.1.gz or anything else? What are the options you give to logrotate?
  • Sandeep Singh
    Sandeep Singh almost 10 years
    Thanks for your help, +1 for the hint.I have updated my question accordingly.
  • Toli
    Toli almost 10 years
    You're welcome. Looking at the new output, it seems logrotate does exactly as told. Except for the dateext part. I would guess, this is because you also provide the start stanza, which is concurrent to dateext (?)
  • Toli
    Toli almost 10 years
    @SandeepSingh If this solved your issue, please consider accepting my answer. Thank you.
  • Sandeep Singh
    Sandeep Singh almost 10 years
    I would have accepted your answer, but unfortunately the issue could not be solved with this description. I am still struggling with this problem.
  • Toli
    Toli almost 10 years
    Hmm, then maybe you should update your question on what the issue is, because as far as i can tell by the output of the ls /var/log/testlog*, testlog was rotated just fine, when you called logrotate with -v instead of -d. Maybe I'm missing something here.
  • Sandeep Singh
    Sandeep Singh almost 10 years
    The exit code of logrotate is still non-zero [1], due to this error: error opening /var/log/testlog.16.gz: No such file or directory
  • Sandeep Singh
    Sandeep Singh almost 10 years
    "testlog.16.gz" was never formed. Why is logrotate failing on this?
  • Toli
    Toli almost 10 years
    It wasn't formed yet. See the updated answer. I agree, that it is rather unfortunate that the program would terminate with an error, since it must be expected that the file does not exist.
  • Sandeep Singh
    Sandeep Singh almost 10 years
    Thanks, I agree with this, but logrotate should not indicate Failure in this case, since this trace just sounds like a false alarm. It is trying to open a file which doesn't exist.
  • Sandeep Singh
    Sandeep Singh almost 10 years
    Don't you feel that this is bug in logrotate? If I run logrotate without '-d/-v' I will just get exit code [1] for this