database pg_dump 输出文件的“权限被拒绝”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21457456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:11:12  来源:igfitidea点击:

"permission denied" for pg_dump output file

databasepostgresqlcommand-linebackuppg-dump

提问by Mostafa Jamareh

i used below command to backup my database

我用下面的命令来备份我的数据库

sudo -u user_name pg_dump dbName -f /home ..../someWhere/db.sql

sudo -u user_name pg_dump dbName -f /home ..../someWhere/db.sql

but it gives me this :

但它给了我这个:

pg_dump: [archiver] could not open output file "/home ..../someWhere/db.sql": Permission denied

pg_dump: [archiver] could not open output file "/home ..../someWhere/db.sql": Permission denied

after googling this issue i find that i must backup my data under the /tmppath , but doesn't work

谷歌搜索这个问题后,我发现我必须在/tmp路径下备份我的数据,但不起作用

how can i resolve this issue ?

我该如何解决这个问题?

thanks in advance,

提前致谢,



i am using Ubuntu 12.04 lts

我正在使用 Ubuntu 12.04 lts

回答by

try pg_dumpfrom psql command-lineas below:

尝试pg_dumppsql command-line如下:

postgres=# \! pg_dump dbName -f /home ..../someWhere/db.sql

回答by Greg

It looks like your pg_dump is working fine, but it is having problems opening the output file as the sudo user. Just guessing, but, if you do the redirection as the user (presumably the one running the pg_dump command) id, that should do it, that is:

看起来您的 pg_dump 工作正常,但是以 sudo 用户身份打开输出文件时出现问题。只是猜测,但是,如果您以用户(可能是运行 pg_dump 命令的用户)身份进行重定向,则应该这样做,即:

sudo -u user_name pg_dump dbName > /home ..../someWhere/db.sql

sudo -u user_name pg_dump dbName > /home ..../someWhere/db.sql

Using this technique your pg_dump will run as the postgres user (assuming that is who user_name is) and the file being written in /home... will be written using the permission of the user running the command (this user might have different permissions than the postgres user).

使用这种技术,您的 pg_dump 将作为 postgres 用户运行(假设这是 user_name 是谁),并且写入 /home... 的文件将使用运行命令的用户的权限写入(此用户可能具有不同的权限) postgres 用户)。

回答by Guardian

Do it from psql command line like below

从 psql 命令行执行,如下所示

-bash-4.1$ pg_dump -Fp dbName -f /home ..../someWhere/db.sql &

-Fselects the format of the output in which pis Output a plain-text SQL script file

-F选择输出的格式,其中p是输出一个纯文本的 SQL 脚本文件

and &at the end will run your backup in the background.

&最后将在后台运行您的备份。