Comments - Rotating Logs on Unix and Linux

4 years, 8 months ago Streamer Cloud

First off, this a useful resource. Probably the best tutorial for Logrotate in general. Very efficient and used what was shared to tweak other log file rotations.

Unfortunately, one error breaks the rotation of logs with Logrotate, and I ran into a few of them, but I was able to solve them quickly.


The following is how I got this to run without errors on Centos 7 with a "mariadb" config file located in: /etc/logrotate.d/mariadb:



/var/log/mysql/* {
        missingok
        create 660 mysql mysql
        notifempty
        daily
        minsize 1M
        maxsize 100M
        rotate 30
        dateext
        dateformat .%Y-%m-%d
        compress
        delaycompress
        sharedscripts 
        olddir archive/
        createolddir 770 mysql mysql
    postrotate
        # just if mysqld is really running
        if test -x /usr/bin/mysqladmin && \
           /usr/bin/mysqladmin ping &>/dev/null
        then
           /usr/bin/mysqladmin --local flush-error-log \
              flush-engine-log flush-general-log flush-slow-log
        fi
    endscript
    su mysql mysql
}


Here the errors I was encountering when using the shared command above verbatim.


error: /etc/logrotate.d/mariadb:1 unknown option 'sudo' -- ignoring line

Since my config file went in /etc/logrotate.d/mariadb, I just removed "sudo tee /etc/logrotate.d/mariadb" and since the <<EOF operator was not reading throughout to the delimiter, I removed all references to "end of file". I am not sure if this is the right situation to use EOD in bash, but I believe they would have to be on inside the curly brackets (or possible outside as an option) to function.


error: /etc/logrotate.d/mariadb:7 bad size '1M # only use with logrotate >= 3.7.4'

error: /etc/logrotate.d/mariadb:7 bad size '100M # only use with logrotate >= 3.8.1'

The commented out notes after the commands were being included within the command, so I removed:

# only use with logrotate >= 3.7.4
# only use with logrotate >= 3.8.1
# only use if your logrotate version is compatible with below dateformat

error: skipping "/var/log/mysql/mariadb.err" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.

error: skipping "/var/log/mysql/mariadb.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.

error: skipping "/var/log/mysql/mariadb-slow.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.

To fix the above permissions errors, I added su mysql mysql after the "endscript" to tell logrotate which user/group should be used for rotation.


error: found error in /var/log/mysql/* , skipping

Letting you know it's going to be skipping this rotation command.


Tiny's comment was spot on. The trailing "}" is also missing. It took me a second glance when I first reviewed this article, but this stood out pretty clear right off the top.


Strange, because in /var/lib/logrotate/logrotate.status the date and time showed up perfect with:

dateformat.%Y-%m-%d-%H-%M-%S

But the archive names came out as:

mariadb.log.2020-01-04-10-%M-%S

So, I choose to slim it down to:

dateformat .%Y-%m-%d


I hope this helps anyone who is looking for it.

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.