Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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

how can i resolve this issue ?

thanks in advance,


i am using Ubuntu 12.04 lts

like image 693
Mostafa Jamareh Avatar asked Jan 30 '14 13:01

Mostafa Jamareh


People also ask

Where is pg_dump output?

sql , which uses the plain or SQL format, the pg_dump command does not store any file anywhere. It just sends the output to STDOUT , which is usually your screen, and it's done. But in your command, you also told your shell (Terminal, Command prompt, whatever) to redirect STDOUT to a file.

Who can run pg_dump?

pg_dump is a regular PostgreSQL client application (albeit a particularly clever one). This means that you can perform this backup procedure from any remote host that has access to the database.

What is pg_dump in PostgreSQL?

pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently. pg_dump does not block other users accessing the database (readers or writers). pg_dump only dumps a single database.

What does the pg_dump command do?

pg_dump is a utility for dumping out a Postgres database into a script or archive file containing query commands. The script files are in text format and can be used to reconstruct the database, even on other machines and other architectures.


2 Answers

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:

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).

like image 57
Greg Avatar answered Sep 22 '22 12:09

Greg


Do it from psql command line like below

-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

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

like image 45
Guardian Avatar answered Sep 20 '22 12:09

Guardian