Jump to content


This topic is now archived and is closed to further replies.


Providing a site backup / export feature like in PhpMyAdmin?

Recommended Posts



I\'d like to provide the administrators for some of the php / mysql websites i\'ve created recently with an option like that found in PhpMyAdmin, whereby they can click \'Backup the Database\' and it will dump the entire database into a gzip file and prompt them where they\'d like to save the file to etc...


Does anyone know how this can be done?


I know PhpMyAdmin creates the dump in the page tbl_dump.php


Does anyone have a small sample of code that does the same thing?


I know the answers are in tbl_dump.php somewhere but theres a lot of code there and a lot of shared values etc....


Any help greatly appreciated :-)

Share this post

Link to post
Share on other sites

hi phpfreak,


I\'m trying out a custom version of that script as i want the user to be prompted to save the file when they click a link rather than display, e-mail or ftp the backup to them..


I\'ve seen some other articles on this so i\'ve tried to tack it all together and this is what i have come up with so far :-






$export_filename = \"mybackup.gz\";


$export_dir = \"/home/matd/public_html/backup\";


$filename = \"$export_dir/$export_filename\";


$dump_buffer = ($filename);


passthru(\"mysqldump --opt -h$server -u$user -p$password $database | gzip >$filename\");


$mime_type = \'application/x-gzip\';


$now = gmdate(\'D, d M Y H:i:s\') . \' GMT\';


header(\'Content-Type: \' . $mime_type);

header(\'Expires: \' . $now);


header(\'Content-Disposition: inline; filename=\"\'. $export_filename . \'\"\');


header(\'Cache-Control: must-revalidate, post-check=0, pre-check=0\');

header(\'Pragma: public\');


echo $dump_buffer;




This does prompt me to save the file but the file is always empty so i\'m half way there! ;-)


Any ideas why the file would be empty? it seems like the passthru isn\'t working but all the required variables have been set correctly and the export feature using phpmyadmin works on the same machine...


Any help greatly appreciated :-)

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.