简体   繁体   English

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

[英]“permission denied” for pg_dump output file

i used below command to backup my database我用下面的命令来备份我的数据库

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

after googling this issue i find that i must backup my data under the /tmp path , 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

It looks like your pg_dump is working fine, but it is having problems opening the output file as the sudo user.看起来您的 pg_dump 工作正常,但是以 sudo 用户身份打开输出文件时遇到问题。 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 -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 用户)。

psql command-line尝试pg_dump如下:

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

Do it from psql command line like below从 psql 命令行执行,如下所示

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

-F selects the format of the output in which p is Output a plain-text SQL script file -F选择输出的格式,其中p是输出一个纯文本的 SQL 脚本文件

and & at the end will run your backup in the background.&最后将在后台运行您的备份。

Just in case somebody else lands here like I did, be aware that pg_dump shows this error too if the folder doesn't exist .以防万一其他人像我一样登陆这里,请注意,如果文件夹不存在pg_dump也会显示此错误 In that case, just create the directory beforehand using mkdir -p folder_name .在这种情况下,只需使用mkdir -p folder_name预先创建目录。

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

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