[thelist] automatic mysql dumps from windows

Burhan Khalid thelist at meidomus.com
Thu Feb 17 00:18:13 CST 2005


Sarah Sweeney wrote:
> Is it possible to set up a scheduled task that will do a dump of a mysql 
> database from windows, without having mysql installed on the windows 
> machine? I have a client who would like to do regular backups of his 
> database with a minimum of installing programs on his computer and 
> without having to perform too many step to get the actual dump file. Ideas?

I think the easiest way (and others hinted at this) would be to run a 
script at the server side that emails the dump file to the user's inbox.

Using your task scheduling program (cron on *nix, etc.) you can have the 
script run daily.  One thing to worry about such scripts is that if you 
access the script from a browser, then it might timeout before the dump 
is complete -- unless you run the script directly from the command line.

Other options include simply piping the output from mysqldump to a file, 
then emailing that file -- crude syntax (probably not correct, but) :

mysqldump -u username -ppassword databasename > outfile.sql | mail 
user at domain.com

A simple PHP script that does the above would be :

<?php

   $database = "mydb";
   $user     = "user";
   $password = "password";
   $today    = date("d-m-Y");

   $email    = "user at domain.com";

   exec('mysqldump -u'.$user.' -p'.$password.' '.$database.' > 
dbDump-'.$today.'.sql');

   $contents = implode("\n",file('dbDump-'.$today.'.sql'));
   mail($email,"Database Dump For ".$today,$contents,"From: Backup 
Monitor <noreply at domain.com>\r\n");
?>

Then you would run this script as :

php -q myscript.php

hth,
Burhan


More information about the thelist mailing list