Search code examples
logrotate

Why logrotate doesn't properly postrotate only has 1 day delay


I have in /etc/logrotate.d/mikrotik :

/var/log/mikrotik.log {
rotate 2
daily
compress
dateext
dateyesterday
dateformat .%Y-%m-%d
postrotate
#/usr/sbin/invoke-rc.d syslog-ng reload >/dev/null
rsync -avH /var/log/mikrotik*.gz /backup/logs/mikrotik/
/usr/lib/rsyslog/rsyslog-rotate
endscript
}

The mikrotik.log.YYYY-MM-DD.gz file is created daily The problem is that rsync in postrotate doesn't copy the last file. For example, on September 25, 2021, there are such files in /var/log:

-rw-r ----- 1 root adm 37837 Sep 24 23:49 mikrotik.log. 2021-09-24.gz
-rw-r ----- 1 root adm 36980 Sep 25 23:55 mikrotik.log. 2021-09-25.gz

and in /backup/logs/mikrotik/ are only:

-rw-r ----- 1 root adm 35495 Sep 23 00:00 mikrotik.log. 2021-09-22.gz
-rw-r ----- 1 root adm 36842 Sep 23 23:58 mikrotik.log. 2021-09-23.gz
-rw-r ----- 1 root adm 37837 Sep 24 23:49 mikrotik.log. 2021-09-24.gz

There is no file mikrotik.log.2021-09-25.gz from Sep 25 23:55 it will not be copied until the next rotation. How to make a file packed today copied by postrotate ?


Solution

  • Problem solved.

    It relied on the order in which the operations were performed. Lgrotate does a 'postrotate' section before compressing to .gz. The solution to the problem was to change the name from 'postrotate' to 'lastaction'.