Anyone want to try a script bash or python? I need to automate master binary log purging to occur so that purging never goes back further than the last slave has the updated info for.

These slaves are mobile and there are 3 of them, and sync whenever the users get around to it.

I can do this manually but how to set this up in a script eludes me.

Any ideas?
DISCLAIMER : Not a Python Programmer

I can give you a generic algorithm

Let's say you have 4 DB Servers


replicator@10.1.2.% is the Replication User
1 Master (10.1.2.10)
3 Slaves (IP Addresses : 10.1.2.20,10.1.2.30,10.1.2.40)


STEP 01) Run this query

SELECT host FROM information_schema.processlist WHERE user = 'replicator';


Collect host columns into a list.

STEP 02) For each host collected into the list, run

SHOW SLAVE STATUS;


and retrieve the Relay_Master_Log_File column. Collect these in an array.

I wrote about why to pick that field and not Read_Master_Log_File


Aug 02, 2012 : Deleting bin logs in replication environment
May 26, 2012 : Trying to understand SHOW SLAVE STATUS\G
Jan 24, 2012 : Mysql master-master replication auto flush old logs 
Jan 03, 2012 : what are the conditions under which mysql replication might break?


STEP 03) Sort the array of Relay_Master_Log_File names. Select the first entry.

Suppose you collected


mysql-bin.00124
mysql-bin.00123
mysql-bin.00125


After sorting, you would pick mysql-bin.00123

STEP 04) Purge binary logs on the Master using the select binary log

PURGE BINARY LOGS TO 'mysql-bin.00123';


That's it.

Give it a Try !!!