logrotate

For logrotate to run daily, you would expect this file to exist...

/etc/cron.daily/logrotate

For the examples on this page to work as expected, the following line is assumed to exist in /etc/logrotate.conf...

include /etc/logrotate.d

MySQL Example

Paste following into /etc/logrotate.d/mysql...

/mysql/data/*log {

# create 600 mysql mysql

notifempty

weekly

rotate 5

missingok

compress

postrotate

# just if mysqld is really running

if test -x /mysql/current/bin/mysqladmin && \

env HOME=/root/ /mysql/current/bin/mysqladmin ping &>/dev/null

then

env HOME=/root/ /mysql/current/bin/mysqladmin flush-logs

fi

endscript

}

For all files ending with log in /mysql/data

Create new files with 600 permissions

Don't rotate if log file is empty

Rotate weekly

Maximum of 5 versions of a file

If the logfile is missing, ignore and continue

Compress old versions with gzip


After Rotate is complete...

... if the mysqladmin file exists...

... and mysqladmin ping says db is up...

... then ...

... flush-logs ...

...

End postrotate commands


NOTE: You need mysqladmin to be able to login locally without needing manual password entry in order for the ping and flush-logs commands to run correctly...

mysql_config_editor set --login-path=mysqladmin --host=localhost --user=root --password