Help - Search - Members - Calendar
Full Version: mysqldump
HTMLHelp Forums > Programming > Databases
asmith
Hey guys

as I said, I need to have mysql backup file , the one I can get by going to my cpanel --> backups , clicking on the database name. the .sql file

I need to get this file by an script. I know mysqldump do it, but isn't it for using by the shell ?

How can i generate such file and save it as an .sql file on the some location on the server?
Thanks
Brian Chandler
How about: ssh to server, type mysqldump. (After checking the manual, so you know which parameters you need.)

Alternatively, surely php has a shell escape, if you want to run it from a web page?

http://jp2.php.net/manual/en/function.shell-exec.php

jimlongo
I use a cronjob to run this script . . . you'd probably need to modify it for your situation

CODE
<?
$datestamp = date("Y-m-d");      // Current date to append to filename of backup file in format of YYYY-MM-DD
/* CONFIGURE THE FOLLOWING SEVEN VARIABLES TO MATCH YOUR SETUP */
$dbuser = "XXXXXXXXXX";            // Database username
$dbpwd = "XXXXXXXXXX";            // Database password
$dbname = "XXXXXXXXX";            // Database name. Use --all-databases if you have more than one
$filename= "../_BACKUP/SQLbackup_myName-$datestamp.sql";   // The name (and optionally path) of the dump file
$command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
$result = passthru($command);
?>

asmith
thanks for the hint biggrin.gif

@jimlongo

that's almost 90% of the thing I want, only difference is, I want to send the file to a mail, so that I would have email full of my database backups .

how do you send that file within an email ?
jimlongo
Try this thread, i think that's where I originally got some of the script from . . . I never could get the mail part of it to work for me.

http://www.lunarforums.com/lunarpages_how_...n-t22118.0.html
asmith
Thanks for the link, it was great.

found out my host doesn't let me run exec or pssthru . Gotta solve it first.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.