Menu
Menu

mysql-bin logs filling up diskspace

Posted in linux, server, srvbox on 2013/11/21
Tags: , , , , , , , ,

In my last article I've documented howto to setup a master-master mysql replication. Though I've configured mysql to clean up the old binlogs, I've realized that such setup will not only consume a lot of diskspace, but also does not guarantee that only the unused binlogs will be removed.

Mysql allows you to configure binlogs cleanup with the following entries in the my.cnf file:
expire_logs_days = 10. This will make sure that all the binlogs which are older than 10 days will be deleted. However they will be deleted even if they could still be needed by the slave. For instance because the slave has some delay and/or was down for whatever reason.

My recommendation is to keep this value rather high, although be careful, because these logs require a lot of diskspace.

In order to cleanup unneeded binary logs I wrote a simple shell script which I'm running from cronjob periodically. The script is basically perfoming the following steps:

  • checking if the slave status is OK,
  • getting the filename of the currently used binary log,
  • purging binary log files upto the current one,
  • If you are using master-master replication it will also (if configured) cleanup the other slave.

If you are interested, the script can be found here.

Comments are closed.