I'm trying to rotate logs produced by CodeIgniter, they are named this way (one per day)
log-2020-05-05.php
log-2020-05-06.php
log-2020-05-07.php
The idea is to package this in a debian package for kalkun. I found this suggestion but it doesn't respond my needs
So what I expect is:
- rotate each log file (which is anyway produced only for that day)
- keep at max 7 days of logs, for ex, on May/07 I would like to have the logs up to May/01, and all previous ones deleted
Result would look like this at max (all previous files are expected to be removed)
log-2020-05-01.php.1.gz
log-2020-05-02.php.1.gz
log-2020-05-03.php.1.gz
log-2020-05-04.php.1.gz
log-2020-05-05.php.1.gz
log-2020-05-06.php.1.gz
log-2020-05-07.php
Is this actually possible with only logrotate ?
The problem is that if I rotate on 'log-*.php' with 'rotate 7', since each file is produced only for a given day, it will actually never rotate a 2nd time, except if I use "create", but that will create empty files, which will pollute the log dir. I could also add "maxage 7" (in addition to "create", but still this will pollute the logdir with empty files)
I tried it this way
/var/www/kalkun/application/logs/log-*.php {
daily
missingok
rotate 7
compress
#create 644 www-data www-data
nocreate
sharedscripts
postrotate
if invoke-rc.d apache2 status > /dev/null 2>&1; then \
invoke-rc.d apache2 reload > /dev/null 2>&1; \
fi;
endscript
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi; \
endscript
}