Help - Search - Members - Calendar
Full Version: cPanel database backup
HTMLHelp Forums > Programming > Web Server Configuration
asmith
hi biggrin.gif

Is there anyway i could get a backup of my mysql database everyday ( or every 12 hours) , and have sent that to an email ?
So that i could have an email full of site database backups in different dates.

I can't see any option for such thing in my cpanel (i'm using a shared server).

Any idea?
Brian Chandler
That simply depends on the service you are given. Does your provider let you run scheduled (cron) jobs? Incidentally, what does "cpanel" mean, exactly? Do you just mean the web-based control page? My provider, pair.com offers such pages, but I can also ssh to the web server and do (more or less) anything I want.

What does "an email" mean? A mailbox? Doesn't sound a very convenient way to store database backups. Of course, you could simply run a "page" that generates a db dump, and save it in a convenient file.
asmith
I can run scheduled (cron) jobs.

i''ll just search to see ow to write such script.

Thanks
jimlongo
Best to search you providers forums. Mine had some good suggestions which lead me to a solution . . . something like this . . . 'course it depends on what commands are available on your server.
CODE
<?
$datestamp = date("Y-m-d");      // Current date to append to filename of backup file in format of YYYY-MM-DD
/* CONFIGURE THE FOLLOWING VARIABLES TO MATCH YOUR SETUP */
$dbuser = "xxxxxxxxx";            // Database username
$dbpwd = "xxxxxxxxx";            // Database password
$dbname = "xxxxxxxx";            // Database name. Use --all-databases if you have more than one
$filename= "../_BACKUP/SQLBU_xxxx-$datestamp.sql";   // The name (and optionally path) of the dump file
$command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
$result = passthru($command);
?>
Brian Chandler
QUOTE
mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename



But the OP said he can run cron jobs, so it should only be necessary to read how to create a cron job to do the above command. (Don't remember the details, but it's something like writing a sequence of time values YMDHM with * for "any", so * * * 18 * means every evening, followed by the command. Seems unnecessary to embed it in a php program, unless you want to trigger it from a browser and read the output?
jimlongo
I guess you could do that, but if you want to add more variables and get anything more complicated isn't it easier to use the cron job to fire the php script
The CPanel cron job interface is pretty simple to just setup the cron job, as you said minute/hour/day/month/weekday/command
CODE
php /home/xxxxx/cronscripts/sql_bu.php



BTW since the OP was asking to have the backup mailed to him, here's the thread where i got what I am using - somewhere in here is what apparently will do that.
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-2024 Invision Power Services, Inc.