MySQL backup

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I've got a feeling that I may have asked this before but I can't find the
answer if there was one offered so apologies for that...

I've written a little content management system and I want to give the user
the ability to back up their database.  I've looked at the relevant pages in
PHPMyAdmin but I'm not any closer to an answer.  I just want something very
simple where they click on a link and it displays a complete dump of the
tables and the inserts for them to copy and paste into a .txt file.

Any ideas please.


Re: MySQL backup

Quoted text here. Click to load it

man mysqldump

DeeDee, don't press that button!  DeeDee!  NO!  Dee...

Re: MySQL backup

Andy Jacobs wrote:
Quoted text here. Click to load it

    php$ cat dbbackup.php
    $db = 'test';
    $table = 'foo';
    /* $table=''; // for all tables in the db */

    echo '<pre>';
    echo `mysqldump -uCENSORED -pCENSORED $db $table`;
    //   ^                                          ^
    //   These are BACKTICKS! They are not single quotes
    echo '</pre>';

    php$ php dbbackup.php
    <pre>-- MySQL dump 9.11
    -- Host: localhost    Database: test
    -- ------------------------------------------------------
    -- Server version       4.0.21-log

    -- Table structure for table `foo`

    CREATE TABLE `foo` (
      `bar` datetime default NULL
    ) TYPE=MyISAM;

    -- Dumping data for table `foo`

    INSERT INTO `foo` VALUES ('2004-01-01 08:00:00');
    INSERT INTO `foo` VALUES ('2004-02-01 08:00:00');
    INSERT INTO `foo` VALUES ('2004-01-01 08:00:01');
    INSERT INTO `foo` VALUES ('2004-02-01 08:00:01');

Mail sent to my "From:" address is publicly readable at /
== ** ## !!                                                         !! ## ** ==
bypass the spam filter. I will answer all pertinent mails from a valid address.

Site Timeline