Jump to content


Photo

Providing a site backup / export feature like in PhpMyAdmin?


  • Please log in to reply
2 replies to this topic

#1 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 26 April 2003 - 10:54 PM

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

#2 phpfreak

phpfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 527 posts
  • LocationEverywhere!

Posted 27 April 2003 - 02:50 PM

You could use this file:



http://www.phpfreaks...ipt/view/11.php
Eric 'phpfreak' Rosebrock
Got LAMP?
http://www.Phpfreaks.com Founder

#3 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 28 April 2003 - 12:57 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users