0

I am using Ubunutu. I simply want to create a postgre dump. So I am using the following command:

sudo -u wap PGPASSWORD="postgres" pg_dump -h localhost -U postgres -d n26n -n public -FC -f /tmp/dump_file --verbose

The above creates a dump as expected. However, since I am running it in verbose mode, I want the output to logged in a file. I tried the following:

sudo -u wap PGPASSWORD="postgres" pg_dump -h localhost -U postgres -d n26n -n public -FC -f /tmp/dump_file --verbose >> logfile

The logfile seems to be empty.

How do I indicate the end of the command?

kosta
  • 153
  • 2
  • 6
  • Have you tried specifying "-f" before `/home/me/dump_file` ? – inaki Apr 19 '17 at 08:38
  • @inaki sorry, I changed the command in the original question. – kosta Apr 19 '17 at 08:42
  • Ok, the you can try using `-E` before the PGPASSWORD variable declaration to make sure sudo preserves the variable you're setting. – inaki Apr 19 '17 at 08:51
  • The logfile is still blank. – kosta Apr 19 '17 at 08:57
  • But you do see output when you don't redirect the output right? I also noticed you changed &> to >> so you are now only redirecting stdout and no longer stderr and stdout. – inaki Apr 19 '17 at 08:57
  • I can see the output when I don't redirect. I tried both &> and >> Both don't seem to work. – kosta Apr 19 '17 at 09:01
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/57329/discussion-between-inaki-and-user3288346). – inaki Apr 19 '17 at 09:39

1 Answers1

1

Without a sample of the output you are receiving I can only make speculations, but your command contains -f (--file) which is where your dump output is going: /home/me/dump_file.

-f file

Send output to the specified file. This parameter can be omitted for file based output formats, in which case the standard output is used. It must be given for the directory output format however, where it specifies the target directory instead of a file. In this case the directory is created by pg_dump and must not exist before.

Any other output would be from stderr beause you have supplied --verbose and so you should redirect this output using 2> logfile1.

--verbose

Specifies verbose mode. This will cause pg_dump to output detailed object comments and start/stop times to the dump file, and progress messages to standard error.

Example:

sudo -u wap PGPASSWORD="postgres" \
   pg_dump -h localhost -U postgres \
   -d n26n -n public -Fc -f /tmp/dump_file --verbose 2> logfile1
Jens Erat
  • 1,400
  • 2
  • 11
  • 26
Phil
  • 111
  • 3
  • He already tried with &> and appearently the logfile is then still empty, this should also redirect stderr (as well as stdout) – inaki Apr 19 '17 at 09:40