Need help backing up a database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Need help backing up a database

Post by pickle »

Hi everyone.

Not sure if this should be here or in the databases forum, but here goes.

I'm having a problem backing up my database from a script. I've got a simple script that just calls:

Code: Select all

shell_exec('mysqldump blah blah');
I get an access denied error.

When I copy the exact string that is the argument to shell_exec and run it on the command line, I get no error, and it works.

I've checked the permissions in the db, and the user I'm connecting with is allowed to connect from both '%' and from 'localhost'.

Any ideas whatsoever?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post by tores »

I got the same 'Access is denied'. Not very strange though, since I was trying to write the dump to a directory instead of a file :oops:
You should also make sure that you're using windows short path names if you're running windows... e.g PROGRA~1 instead of Program Files... dir /X displays short names

regards tores

PS: Somewhere I read that backing up your db with shell_exec consumes a lot of memory. You should use system or exec instead.
Last edited by tores on Tue Aug 02, 2005 11:15 am, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Thanks. I'm using Linux so that's not a problem.

I'm pretty sure there's nothing wrong with the command, because when I run the exact same command on the command line, it works fine.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

Hi Pickle

I'm no php genius, so ignore me if any of my suggestions are stupid.

tores said:
You should also make sure that you're using windows short path names if you're running windows... e.g. PROGRA~1 instead of Program Files... dir /X displays short names
I had a problem that there was a space in the directory name that was in my execute path. E.g. /var/lib/my program -l blah. Fixed it with something like /var/lib/"my program" -l blah

Other than that, if you are running apache, the server is it's own user, as I understand it. So when you execute the command in the shell, you are a different user than that which is executed through php served by the apache web server.

So just make sure that your ownership is correct.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Not all php runs as apache - this script is run by the CGI version of PHP. So, the file is run as a cron job (meaning: as root). So, it's not a permissions thing. Even if it was, I don't think it's Linux permissions because the file is generating a MySQL error, not a shell error.

Thanks though - I can use all the brainstorming I can get.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

well MAYBE you dont have full permission on that database for that user from php....uhhhhh maybe be probebly not. i mean maybe there is another user that is being run from the php script and a different user from command line but probebly not. just thought i would put my 2 cents in
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

It might be a path var issue. If you call mysqldump at the command line the standard paths are available. If you call it by the script they might not. Provide the full path to mysqldump and it might work.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Thanks, but that didn't help either - same old access denied error.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply