k102
k102

Reputation: 8079

empty output when calling pg_dump under php code

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_alarm > /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?

Upvotes: 1

Views: 1387

Answers (1)

onteria_
onteria_

Reputation: 70567

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.

Upvotes: 3

Related Questions