View Full Version : --all-databases backup
This isn't working.
echo system("$path mysqldump --all-databases> all_databases.sql");
It creates a file, but it's contents are:
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
I'm running XAMPP 2.0 on Linux.
I also tried adding -HOST -uUSERNAME -pPASSWORD, and that didn't work, and I tried using the MySQL_connect() function, and that didn't work.
NXArmada
03-10-2008, 12:36 PM
<?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 --all-databases | gzip > $backupFile";
system($command);
include 'closedb.php';
?>
Thanks for the response. :)
I saw that page, and I still couldn't figure it out. For one, what's the contents of the included files? I imagine a MySQL connect and close in two of them, but what's the third?
NXArmada
03-11-2008, 08:06 PM
Config.php
<?php
// This is an example of config.php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'phpcake';
?>
opendb.php
<?php
// This is an example opendb.php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>
closedb.php
<?php
// an example of closedb.php
// it does nothing but closing
// a mysql database connection
mysql_close($conn);
?>
Thank you very much! So you have to connect to MySQL and include the information in the --all-databases command? I'll try and see what happens.
This still didn't work:
<?php
$conn = MySQL_connect('localhost','username','password');
MySQL_select_db('a_db');
system("/opt/lampp/bin/mysqldump mysqldump --opt -h localhost -u username -p password --all-databases > backup.sql")
or die('DID NOT WORK!');
MySQL_close($conn);
?>
It prints:
DID NOT WORK!
And backup.sql's contents are:
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
NXArmada
03-12-2008, 12:56 PM
You have mysqldump 2x's
/opt/lampp/bin/mysqldump mysqldump
remove the second mysqldump at the end
Thanks again, but now the file "backup.sql" is completely empty. Am I doing something else wrong?
Thank you again for all of your help. After a few hours googling through forum after forum, I found the answers I was looking for-- turns out I had more then one problem. Some were related to the script, others were the server configurations. In any case, it works, so I'm happy :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.