We have a slightly smarter script which checks each slave to find the
furthest one behind and purges up to that number.  However, it currently
figures out who the slaves are by checking a process status on the
master.  Unfortunately, this doesn't work if one of your slaves is down. 
So, I'm going to rewrite it to check the known slaves.

-Marc

Jeremy Zawodny wrote:
> 
> On Tue, Apr 09, 2002 at 10:15:12AM +0200, paul wrote:
> > Hello all,
> >
> > I have setup a replication between two MySQL v4.01a servers on
> > FreeBSD, which works really fine. The only problem is that since we
> > have MANY updates on the master database, the bin-logs grow very
> > fast. We need to do a manual clean-up at least once every other day,
> > otherwise the disk space will get exhausted: "SHOW SLAVE STATUS" on
> > the slave, write down the 'Log_File' name, and pass that to "PURGE
> > MASTER LOGS TO 'logname'" on the master.
> >
> > Does anybody have an idea how we could automate this procedure, or
> > should we manage the log-files is another way?
> 
> Here's a quick home-grown solution that works well for us.  It's not
> the smartest approach, but we never let a slave get too far behind
> (they're all closely monitored), it works qutie well.
> 
> This is purge_master_logs:
> 
> ---snip---
> 
> #!/usr/local/bin/perl -w
> #
> # $Source: /CVSROOT/yahoo/finance/mysql/bin/purge_master_logs,v $
> 
> ## On a mysql server, purge the replication logs if there are "too
> ## many" sitting around and sucking up disk space.
> 
> $|++;
> 
> use strict;
> use RunMutex '/tmp/.write_heartbeat.lock';
> use DBIx::DWIW;
> 
> my $MIN_LOGS = 4; ## keep at least three binary logs around
> 
> my $db = DBIx::DWIW->Connect(
>                             DB   => "mysql",
>                             User => "root",
>                             Pass => "password",
>                             Host => 'localhost',
>                            );
> 
> if (not $db)
> {
>     die "Couldn't connect to database!";
> }
> 
> my @logs = $db->FlatArray("SHOW MASTER LOGS");
> 
> ## see if there are enough to bother
> 
> if (@logs < $MIN_LOGS)
> {
>     exit;
> }
> 
> ## if so, figure out what the last one we want to kee is
> 
> my $last_log = $logs[-$MIN_LOGS];
> 
> print "last log is $last_log\n" unless $ENV{CRON};
> 
> ## and purge the rest
> 
> $db->Execute("PURGE MASTER LOGS TO '$last_log'");
> 
> exit;
> 
> __END__
> 
> ---snip---
> 
> Jeremy
> --
> Jeremy D. Zawodny, <[EMAIL PROTECTED]>
> Technical Yahoo - Yahoo Finance
> Desk: (408) 349-7878   Fax: (408) 349-5454   Cell: (408) 685-5936
> 
> MySQL 3.23.47-max: up 61 days, processed 1,654,071,336 queries (311/sec. avg)
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <mysql-unsubscribe-##L=##[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <mysql-unsubscribe-##L=##[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to