Reputation: 10898
I am trying to do a mysql dump via php.
This is the code
$backupFile = $table. "-". date("Y-m-d-H:i:s") . '.gz';
//Command nog aanpassen....
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
//$status = system($command);
echo $backupFile ."<br>";
$status = passthru($command, $a);
echo "output:" . $a;
The value of $a = 2. But I can't find what it means. I also can't find the backup file anywhere.
Any idea's?
Upvotes: 0
Views: 1449
Reputation: 1
Could also be your backup's destination. Make sure the user you're running mysqldump as (in your case likely www-data, or some other apache user) has write permission to the directory where you're trying to write your backup. A lot of times I'll try a command from the command line.. and see it work fine.. but I'm root, or my user.. not www-data.
Upvotes: 0
Reputation: 21396
I'm not sure if this is the problem, but it looks like your password passing parameter is incorrect.
If you use -p you need to have the password right next to it, without whitespace, like so:
$command = "mysqldump --opt -h $dbhost -u $dbuser -p$dbpass $dbname | gzip > $backupFile";
Or use the long --password=$dbpass.
For example:
$command = "mysqldump --opt -h $dbhost -u $dbuser --password=$dbpass $dbname | gzip > $backupFile";
From the mysqldump man page:
--password[=password], -p[password]
The password to use when connecting to the server. If you use the short option form (-p), you cannot have a space between the option and the password. If you omit the password value following the --password or -p option on the command line, you are prompted for one.
Upvotes: 2