MySQL Forums
Forum List  »  Backup

stopping/starting slave while mysqldump'ing
Posted by: Ajay Sharma
Date: January 12, 2006 03:50PM

I wrote a quick php script to do my mysql backups. It goes like this:

- connect to slave db
- get a list of databases
- do a "SLAVE STOP"
- then run a bunch of mysqldump commands for each database
- do a "SLAVE START"

I'm fairly new to replication, is it pretty safe to start/stop the slave like that?

--Ajay

PS. here's the 0.1 version of the script in case anyone was curious:

---cut here----
#!/usr/bin/php -q
<?php

$user = '';
$pass = '';
$host = '';

$date = date("Ymdhm");

$dir = '/backup/dumps/per_db/';

$conn = @mysql_connect( $host,$user,$pass) or die( mysql_errno().': '.mysql_error());

// before we begin, stop the slave
$result = mysql_query("slave stop") or die('Slave Stop failed: ' . mysql_error());

$result = mysql_list_dbs( $conn );


// now dump each database
while( $row = mysql_fetch_object( $result ) ):
$db = $row->Database;
$filename = $dir . $date . "_" . $db . ".sql.tgz";

$command = "mysqldump -h $host -u$user -p$pass --opt -C $db | gzip -c > $filename";
echo "$command\n";
system($command);

endwhile;

mysql_free_result( $result );

//start up the slave before we leave
$result = mysql_query("slave start") or die('Slave Start failed: ' . mysql_error());
mysql_close( $conn );

?>

Options: ReplyQuote


Subject
Views
Written By
Posted
stopping/starting slave while mysqldump'ing
3225
January 12, 2006 03:50PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.