Thread: MySQL backup
View Single Post

  #2 (permalink)  
Old 11-16-2004
Pedro Graca
 
Posts: n/a
Default Re: MySQL backup

Andy Jacobs wrote:
> ... I want to give the user
> the ability to back up their database.
> ...
> 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.


php$ cat dbbackup.php
<?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');

</pre>
php$
--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com/
== ** ## !! !! ## ** ==
TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address>) may
bypass the spam filter. I will answer all pertinent mails from a valid address.
Reply With Quote