Reputation: 1047
i have to transfer a created sql file from server a to server b. Currently i tried following without success:
// Some SQL executions to fill and update the tables
( .. )
// Filename pattern
$fileName = "dump_".date("Y-m-d-H_i_s").".sql";
// Dump the tables and saves the output in dump directory
$dump = "mysqldump -u$USER -p$PASS $DB ".$this->dumpTables." > " . $this->path."dumps/". $fileName;
// Transfer the lastest sql file to the origin
$command = "scp " . $this->path."dbbackup/" . $fileName . " [email protected]:/PATH/dumps" . $fileName;
system($command, $retvalOrigin);
if ($retvalOrigin != 0) {
fwrite($this->logFileInstance, $this->date() . "Something went wrong! \r\n");
fwrite($this->logFileInstance, $this->date() . "$command! \r\n");
}
Whats the problem?
If i execute the command by hand, everything goes fine. So there is no permission problem. No unexpected log entries in my error log. If i copy the command without any vars and put this into a new php file, and call this, there is no error again.. At first i thougt scp hates me, thats why i replaced the "scp" with "rsync -ave". That gives me no error, but won't copy the file to the origin server (No error log again!).
scp -> $retvalOrigin = 1, no file on origin server, no error log
rsync -> $retvalOrigin = 0, no file on origin server, no error log
So what's the point?
Edit:
Path are ABSOLUTE, SSH KEY for the executing user and www-data - no login required anymore, $retVal includes ONLY 1 / 0, and NO in won't use for that a cron
Upvotes: 0
Views: 132
Reputation: 104
Make sure that the user that uses the scp command (most likely www-data) has the permissions to use scp without authentification and not only your system user.
Also make sure that you use absolute paths.
For better error reporting use 'exec' for storing the error messages. 'system' will output the error directly and will get lost most likely when you use it in a cron.
exec($command, $commandOutput, $retvalOrigin);
Furthermore you can try shell_exec if the command needs a valid shell.
Upvotes: 1