logrotate - archive log files

Astra records information about its status, results and errors in the log file. Standard location of logs in the folder /var/log/

With the help of log analysis you can understand what works wrong, why the error occurred and how to solve the problem. But here lies one problem. The size of logs is constantly growing and they take more and more disk space, so you need time to clean logs and delete outdated records, so they do not interfere with normal operation. You can do this manually from time to time or configure Cron scripts, but there is an even simpler option - the logrotate utility.

create the file /etc/logrotate.d/astra with content:

/var/log/astra.log {
su
daily
rotate 3
size 5M
compress
delaycompress
missingok
nocreate
nomail
notifempty
copytruncate
}

/var/log/astra.log - which log file to work with
su - working on behalf root
daily - perform rotation every day
rotate 3 - number of archives
size 5M - perform the rotation if the size is over 5 megabytes
compress - to compress the file
delaycompress - do not compress the last and penultimate log
missingok - оmissing file is not an error
nocreate - do not create empty file
nomail - do not notify and do not send the latest logs in mail
notifempty - do not process empty files
copytruncate - after creating the copy, trim the original log file instead of moving the old log file and creating a new one

To apply the changes immediately, run the following command:

logrotate /etc/logrotate.conf

To check the changes you need to run the command (no action will be performed with the logs):

logrotate -d /etc/logrotate.conf

Logrotate setup is complete