asmith
Oct 29 2008, 06:46 AM
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
Oct 29 2008, 07:44 AM
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
Oct 29 2008, 11:44 AM
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
Oct 29 2008, 03:36 PM
thanks for the hint

@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
Oct 29 2008, 04:30 PM
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
Oct 31 2008, 11:36 PM
Thanks for the link, it was great.
found out my host doesn't let me run exec or pssthru . Gotta solve it first.