Page 1 of 1
Need help backing up a database
Posted: Tue Aug 02, 2005 10:59 am
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?
Posted: Tue Aug 02, 2005 11:09 am
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
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.
Posted: Tue Aug 02, 2005 11:15 am
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.
Posted: Tue Aug 02, 2005 5:13 pm
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.
Posted: Tue Aug 02, 2005 5:17 pm
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.
Posted: Tue Aug 02, 2005 5:39 pm
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
Posted: Wed Aug 03, 2005 4:25 am
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.
Posted: Wed Aug 03, 2005 9:51 am
by pickle
Thanks, but that didn't help either - same old access denied error.