0

Is it possible to use PHP and a mysql query combined to allow a whole database backup file to be downloaded?

For example, I'm currently backup up my database by using the export tool in phpmyadmin, but what if I wanted to add a button or link on my site which would essentially allow me to do the same thing?

The backup has to appear as an SQL file btw

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by diafol
0

Is it possible to use PHP and a mysql query combined to allow a whole database backup file to be downloaded?

For example, I'm currently backup up my database by using the export tool in phpmyadmin, but what if I wanted to add a button or link on my site which would essentially allow me to do the same thing?

The backup has to appear as an SQL file btw

Hello,

If you follow the normal standards for config files for php something like this should work.

Source code : config.php , opendb.php, backitup.php

<?php
// This is an example of config.php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'phpcake';
?>
<?php
// This is an example opendb.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
mysql_select_db($dbname);
?>
<?php
// This is an example of backitup.php
include 'config.php';
include 'opendb.php';

$backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
system($command);
include 'closedb.php';
?>
0

system() may be disabled on your webserver for security reasons. Worth a try though.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.