Forum Moderators: coopster

Message Too Old, No Replies

mysqldump not working

         

jackvull

11:38 am on Sep 14, 2005 (gmt 0)

10+ Year Member



Hi
My hosting provider claims that this script worked when they ran it manually. They also mentioned that they had to remove some whitespace to get it to work. I cannot see any problem with the script now, but it still does not work when called directly from a browser. Any ideas?
The script and the folder it is writing to are chmod'ed to 755:

<?php
$cmd1 = "/usr/bin/mysqldump -hsome.server.net -uusername -ppassword --all-databases > /home4/sub002/sc11883-LGVN/www/Backups/a.sql";

system($cmd1);

echo "Done";
?>

Romeo

12:18 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



hmm ... can you be a bit more specific about the "not working"?
There may be several problems: with the shell command, with mysql, or with the php-environment of your web server. Did you check the httpd server's error_log?

Look into the $ret value for the status code of the executed command. Additionally, system() returns the last line of the command output on success, and FALSE on failure.
$lastline = system($cmd, $ret);
echo "lastline $lastline, ret $ret\n";

If you need more output to diagnose your error, use the passthru() or exec() functions instead, where an array will returned with all output of the executed command.

Regards,
R.

jackvull

12:41 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



Sorry, what I mean by "not working" is that the a.sql file is not created by I don't get any PHP errors reported on the screen either.

Using the retval return code I get 127 and just a blank whitespace is printed for the $lastline.

I tried passthru() but get nothing. Is there an easy way to use exec() and echo out the array it creates?

jackvull

12:56 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



The script is being called from the webserver but as it's the hosting company, I don't have access to the error log.

bcolflesh

1:22 pm on Sep 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's probably timing out - you could try changing "max_execution_time" with ini_set, if your provider allows it:

[phpbuilder.com...]

Romeo

1:54 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



Sorry for your error_log. However, it should be possible for the hosting company to supply a custom error log for each virtually hosted domain.
Alternatively, you could set this at the beginning of your script to get errors to the screen:
error_reporting(E_ALL);
ini_set('display_errors',1);

The return code 127 could be a "program not found at this path" condition, or could be a result from a php safe_mode setting (don't have safe_mode here, so I can't help you here. Do a phpinfo() to see what you have).
A short look into the error_log would help here a lot.

I don't know, if a timeout would also generate a 127.
How long are you waiting until you see the 127 coming back?

To see the output of the exec(), try this:
exec($cmd,$array,$ret);
$output = join('<br>\n',$array);
echo $output;

Regards,
R.

jackvull

3:18 pm on Sep 14, 2005 (gmt 0)

10+ Year Member



It's not a timeout as it completes within a few seconds.
They have talked about turning safe_mode off but I am worried about the security implications of this? Are there any drastic ones?

jackvull

8:52 am on Sep 16, 2005 (gmt 0)

10+ Year Member



The host has now disabled safe_mode but the script now returns a status of 1.
They say there is no set error log for my virtual host as everything is on shared servers.
I know the status of 1 could mean a number of things but any likely solutions?

Romeo

10:26 am on Sep 16, 2005 (gmt 0)

10+ Year Member



Hi Jack,

sorry, I am running out of ideas.
You surely need to know more about the errors occuring.
Try expanding your $cmd1 by this:
"mysqldump ...... 2>&1"
to get errors redirected from STDERR to STDOUT.

Hopefully this may help to get some additional insights on your problem.

Regards,
R.

jackvull

11:33 am on Sep 16, 2005 (gmt 0)

10+ Year Member



I use that command and the full dump comes onto the browser as text...so I see all the CREATE DATABASE if exists stuff.

The return value is then 0 on the final line.

Must be something to do with the creation of the a.sql file?

Romeo

12:09 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



So at least you now know that your command is working ... :-)
Yes, you may check under which user the script is running (most likely the apache, depending on the serve setup; a common user name of it could be wwwrun), and if it is different to the owner of the directory the file should be written to, and how are the permission settings of that directory. You would need a full 777 (read/write/execute for "world") on the directory, if the apache is an 'other' user for that directory.
You could see this ownership and permission information in a native ftp client or by throwing an exec("ls -la" ...) from php.

Regards,
R.

jackvull

12:39 pm on Sep 16, 2005 (gmt 0)

10+ Year Member



That did it - I set the Backups folder to 777 and the file has now been created there (it was 755 before).

Thanks!