added purge script for master/slave db

This commit is contained in:
following
2013-02-13 01:20:55 +01:00
parent d15ee5f962
commit f9b8723e3d
3 changed files with 47 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
This directory contains files which will reside outside the code directory tree
on a production system.
@@ -0,0 +1,45 @@
#!/usr/bin/php -q
<?php
/***************************************************************************
* You can find the license in the docs directory
*
* Cronjob to clean up master logs that we dont need any more for any
* configured slave server. Run this script once every day.
*
* The user account given below needs SUPER privileges.
* This is why you want to place this file outside PHP open_basedir
* and restrict read access to the root user.
***************************************************************************/
// begin configuration
$dbserver = '';
$dbname = '';
$dbuser = '';
$dbpassword = '';
// end configuration
$dblink = @mysql_connect($dbserver, $dbuser, $dbpassword);
if ($dblink === false)
exit;
if (mysql_select_db($dbname, $dblink) == false)
{
mysql_close($dblink);
exit;
}
$rs = mysql_query("SELECT COUNT(*) AS `c` FROM `sys_repl_slaves` WHERE (`active`=1 AND `online`=0) OR (`active`=1 AND `online`=1 AND `current_log_name`='')", $dblink);
$r = mysql_fetch_array($rs);
mysql_free_result($rs);
if ($r[0] == 0)
{
$rs = mysql_query("SELECT MIN(`current_log_name`) FROM `sys_repl_slaves` WHERE `active`=1 AND `online`=1", $dblink);
$rLastLog = mysql_fetch_array($rs);
mysql_free_result($rs);
mysql_query("PURGE MASTER LOGS TO '" . mysql_real_escape_string($rLastLog[0], $dblink) . "'", $dblink);
}
mysql_close($dblink);
?>