Jump to content

Providing a site backup / export feature like in PhpMyAdmin?


Recommended Posts

Hi,

 

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 :-)

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 :-

 

<?php

 

include(\"../../config/config_sql.php\");

 

$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 :-)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.