PDA

View Full Version : mySQL Backup via php


122222
05-05-2008, 01:02 AM
First i came across this website:http://www.tech-geeks.org/geeklog/article.php?story=2005031409340971

the first script is just what i needed so i modified it and uploaded it to my ftp. then with my web browser, i went to the location of the script (php). It would only allow me to download the script. Here is the script I used (modified it accordingly before upload):

#PHP CODE
$host = 'localhost';
$dbuser = 'db_user';
$dbpword = 'db_password';
$dbname = 'db_name';
$backupFile = date("Y-m-d") . '.gz';
# Use system functions: MySQLdump & GZIP to generate compressed backup file
$command = "mysqldump -h$host -u$dbuser -p$dbpword $dbname | gzip> $backupFile";
system($command);
# Start the download process
$len = filesize($backupFile);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/gzip");
header("Content-Disposition: attachment; filename=$filename;");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
@readfile($backupFile);
# Delete the temporary backup file from server
unlink($backupFile);


Needless to say, I got nowhere. Would appreciate help as to how to download the mysql database using script (php) uploaded to ftp on site and web browser. Preferably, I would like the script to open a download dialog with the database file (compressed or not, it doesnt matter) allowing me to download it to my local computer. And yes, Im okay with the security problems with that.

Fumigator
05-05-2008, 04:43 PM
This is really a PHP question.

Does your web server have PHP installed? Did you name your script with a PHP extension so your installation of PHP would parse the file? Do you have <?php ?> opening and closing tags in the script? Have you ever successfully run a PHP script on your web server?

Try a dead-simple PHP script, see if you can get it to parse correctly.


<?php
echo "Hello world";
?>