简体   繁体   English

在 php 代码下调用 pg_dump 时为空 output

[英]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:我需要通过 php 中的 pg_dump 进行转储,所以我有一个 function 像这样:

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.问题是mon_alarm.sql文件是空的。 But when i execute this command via command line everything works fine.但是当我通过命令行执行这个命令时,一切正常。 What should i change to create a dump in php?我应该更改什么以在 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.如果您在标准网络服务器设置下运行 PHP,那将不起作用,因为它将在网络服务器用户的上下文中运行,因此 sudo 不会让您像那样更改用户上下文。

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.如果这是一个脚本,您将不得不调整 sudo 以pg_dump命令作为用户的无密码 sudo 权限运行,否则您的 sudo 命令将提示输入密码并破坏您的自动化过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM