Re: Getting empty .sql file when we run backup code please see the code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



First, let me say... that I'm using MAMP on a Mac... so the location of mysqldump is most 
likely different than what you're using... but when I reduced your code down to just 
executable lines... and only those necessary to DO the backup I came up with the 
following below (with a few enhancements).

On the mysqldump command I should note... that you had THREE '-', rather than two.
e.g. you had:  ---user  where you should have had --user  You also were NOT sending 
the file anywhere.  You need to add '> '.$backupFile;

Also, use the 'echo $command' line... to output your command... and then cut-n-paste it 
to the command line to insure that it functions properly.

<?php

$dbname = 'dbname' ;
$dbuser = 'user';
$dbpass = 'password';
$dbhost = 'localhost';;

$datetime = date ('Ymd_His');
$backupFile = '/tmp/'.$datetime.'-'.$dbname.'.sql';
$mysqldump = '/Applications/MAMP/Library/bin/mysqldump';

$command = $mysqldump." --user ".$dbuser." --password=".$dbpass." ".$dbname." > 
".$backupFile; 

echo "command = ".$command."\n";

exec ($command, $retval);
var_dump ($reval);

?>




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux