D
D
Dana2019-02-19 15:20:04
linux
Dana, 2019-02-19 15:20:04

How to configure logrotate correctly?

Due to the rapid growth in the size of log files, it is necessary to organize archiving and deletion of old log files.
For this I decided to use logrotate.
# /etc/logrotate.conf

/var/logs/*.log {
su root root
weekly
rotate 5
compress   
delaycompress
missingok    
notifempty
olddir /tmp/old_logs/
#sharedscripts   
#postrotate
#       find /tmp/old_logs/ -name “*.gz” -mtime +30 -print0 | xargs -0 rm -f
#   endscript
}

But the rotation stops working after the second launch. On first run, the files are moved to olddir with the rotation date added to the file name. On the second run, the files that are in olddir are compressed. And after that, the rotation no longer occurs until all the creation of archives are manually deleted.
How to properly set up rotation so that it works smoothly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Chernykh, 2019-02-19
@sashkets

I write the logs of each service in a separate folder, it's more convenient
/var/log/cron/, /var/log/maillog/, etc.
therefore, I don’t experience any difficulties in moving like you do,
and the su root root line is incomprehensible if logrotate is already started by root

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question