Logrotate to clean up date stamped files

后端 未结 6 1104
梦谈多话
梦谈多话 2021-01-31 17:22

I\'m currently trying to work out a method of tidying up Oracle Recover log files that are created by Cron...

Currently, our Oracle standby recover process is invoked b

6条回答
  •  不要未来只要你来
    2021-01-31 17:57

    As per @Jan Vlcinsky, you can let logrotate add the date - just use dateyesterday to get the right date.

    Or, if you want to put in the date yourself, you can 'aim' at the name without the date , and then the names with the date will be cleaned up.

    However, what I found is that if I don't have a log file there, logrotate doesn't do the cleanup of the files with dates.

    But if you're prepared to have an empty log file lying around, then it can be made to work.

    For example, to clean up /var/log/mylogfile.yyyymmdd.log after 7 days, touch /var/log/mylogfile.log, then configure logrotate as follows:

    /var/log/mylogfile.log
    {
            daily
            rotate 7
            maxage 7
            dateext
            dateformat .%Y%m%d
            extension .log
            ifempty
            create
    }
    

    This entry, combined with the existence of mylogfile.log, triggers logrotate to clean up old files, as if they had been created by logrotate.

    daily, rotate plus maxage cause old log files to be deleted after 7 days (or 7 old log files, whichever comes first).

    dateext, dateformat plus extension causes logrotate to match our filesnames.

    And ifempty plus create ensure that there continues to be an empty file there, or the log rotation would stop.

    Another tip for testing, be prepared to edit /var/lib/logrotate.status to reset the 'last rotated' date or logrotate won't do anything for you.

提交回复
热议问题