Logrotate don't move file to oldlogs folder and exit abnormally with code 1.
I tried to launch manually it with -d option but no errors are showed.
This is my configuration:
/var/log/myfolder/*.log
{
rotate 4
daily
missingok
size=100M
notifempty
copytruncate
compress
delaycompress
create 640 root root
dateformat -%Y-%m-%d-%s
sharedscripts
postrotate
mv /var/log/myfolder/*.gz /var/log/myfolder/oldlogs/
/etc/init.d/rsyslog restart
endscript
}
Any idea?
I have many files that are updated continuously and I would like to have the compressed files in another directory ( oldlogs) to storage purpose. Rotate command is unnecessary for my purpose but my problem is that I can't move files to oldlogs directory.
Best Answer
You don't need to move the old logs files yourself, log rotate does this for you.
You don't want to restart rsyslog in your
postrotate
script unless you're rotating logs being written from rsyslog. If that is the case, you don't need to perform a full restart of rsyslog, instead usekill -HUP $(cat /var/run/rsyslogd.pid)
(assuming that's the pid of rsyslog).The goal is to get the service to stop trying to write to the old file handler and start writing to the new log file.
If you're trying to logrotate a log written by another service,
-HUP
may not be supported.What's the driver for using
copy truncate
? That's a bit exotic.Further details are in the man page for
Logrotate
https://manpages.debian.org/jessie/logrotate/logrotate.8.en.html