Forum Moderators: coopster

Message Too Old, No Replies

Mysqldump not working from php script but command line

Mysqldump not working from php script but command line

         

phparion

2:12 pm on Nov 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Hi

i am executing a php script from command line under cron job. it used to work fine before but it has started giving problems now.

here is the error i am getting when i execute it from command line

#php dump.php
sh: /mysqldump: No such file or directory

i have plesk installed on this server.

the code within my dump.php in question is as follow

exec("mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName");

I tried the same using system() and shell_exec() but the same error as above. I even tried with full path as

exec("/usr/bin/mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName");

but get the same error. I have checked the mysqldump and mysqldumpslow are present in /usr/bin/

when i print the above command and execute it directly from commandline then the command works fine.

I have googled a lot for this error but have failed to get any clue.

can anybody help please?

Alcoholico

5:09 pm on Nov 28, 2008 (gmt 0)

10+ Year Member



You should try


cd /usr/bin/;
exec("./mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName");

phparion

5:51 pm on Nov 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you for your reply. I think you missed this

exec("/usr/bin/mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName");

in my post. It means I tried to activate mysqldump from bin/ but it gives the same error. on the command line however, no matter wherever i am the same command works fine without any problem . just in the php script it gives me error.

vincevincevince

8:28 am on Nov 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is a strange problem... my guess is that your PHP settings are to blame; safe_mode being on or similar.

Check:

php --info

Look for these parts (and post if problem not solved):


safe_mode
safe_mode_exec_dir
Configuration File (php.ini)
Loaded Configuration File

In the meantime - why not run your mysqldump command from a shell script instead of via PHP? CRON will run that just fine - dump the result to your temp file as you do now and have PHP run five minutes later to play with it if PHP processing is required.

Alcoholico

3:06 pm on Nov 29, 2008 (gmt 0)

10+ Year Member



Yes, I missed something, it should be:

exec("cd /usr/bin/");
exec("./mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName");

Or, as suggested by vincevincevince create a shell script and call it via cron or even via another php script.
I'd put in the shell script


cd /usr/bin
./mysqldump -u$dUser -p$dPass $database ¦ gzip -9 > /home/s3temp/$dName

Of course, in this case, user, password and db need to be harcoded.
Save it as name.sh chmod to make the text file executable and call it from a php script.

<?php
exec("/usr/bin/name.sh");
?>

Hope that helps.

phparion

11:44 am on Nov 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't want to show back to this error, it was working fine before. Our hosting company upgraded some stuff lately and after that it has left working. It has to do something with Linux - PHP configuration.

Secondly, I have shown you a simple command of php script, I have a full fledge php software that runs periodically on our three servers, backs up all websites and their relative databases, then pack them into a single .tar.gz file and connect with Amazon S3 Storage service, create a new bucket by the name of current day, shift the file from our server to Amazon server, then on successful shift, remove the temporary back up files from our server to free resources.

Similarly another part of the same php software runs every 6 months to connect to amazon server, delete backup files older than last six months, to keep our amazon account free of unnecessary old back ups.

So it is a full software that I have written in PHP after very hard work of two months. I dont want to show back to this simple one line error :D try to feel for me...

anyway, I am looking to solve this to learn new thing too. because it used to work before so i have a great hope to fix it.

thank you for your replies

phparion

2:40 pm on Dec 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i fixed it ! sometimes complex problems have very simple solutions... my php was running in safe mode after my last upgrade to latest version of php and apache. I set it to OFF and it started working. thought to write here in case if anybody face the same problem as i am facing in future. i dont want him to waste lots of time as i did :)

Alcoholico

6:08 pm on Dec 1, 2008 (gmt 0)

10+ Year Member



Glad to learn you fixed it. As usual vince was right.