I need to make a dump via pg_dump in php so i've got a function like this:
function fnDump()
{
exec("/usr/local/bin/sudo -u pg_user /usr/local/bin/pg_dump mon_al开发者_如何学JAVAarm > /usr/home/user/monitor_test/renew_db/mon_alarm.sql",$out);
var_dump($out);
}
The problem is that mon_alarm.sql
file is empty.
But when i execute this command via command line everything works fine.
What should i change to create a dump in php?
If you're running PHP under a standard webserver setup, that won't work because it will run under the context of the webserver user, so sudo won't let you change user context like that.
If this is a script you're going to have to adjust sudo to run only the pg_dump
command as passwordless sudo permissions for the user, otherwise your sudo command will prompt for a password and ruin your automated process.
精彩评论