0

I'm trying to restore a database from a text file. I'm following the answer on this question. How do I restore a plain text postgres .backup file

But add: > c:\result.txt

psql.exe -U  sde sde < c:\backup\sde_04_06_2018.backup > c:\backup\result.txt

This seem to work but doesn't write the errors.

You get messages like this on the text file:

REVOKE
GRANT
SET
ALTER DEFAULT PRIVILEGES
ALTER DEFAULT PRIVILEGES

But on the command windows you see error like this:

ERROR:  constraint "sde_layer_stats_version_id_fkey" for relation sde_layer_stats" already exists
ERROR:  constraint "xml_columns_fk1" for relation "sde_xml_columns" already exists
ERROR:  constraint "xml_columns_fk2" for relation "sde_xml_columns" already exists
ERROR:  constraint "xml_indextags_fk1" for relation "sde_xml_index_tags" already exists

The idea is save the error on the text file so I can review and decide if are something I need to handle.

enter image description here

2

I want help with how write the command line so I can save the output of the restore to a file.txt. So the create/insert/alter on the backup aren't relevant. And the image is just as reference, I also include the message as text just in case.

If you're asking how do you put the error to the "result file" too, you need to redirect STDERR as well as STDOUT or direct STDERR to STDOUT with 2>&1

psql.exe -U  sde sde < c:\backup\sde_04_06_2018.backup > c:\backup\result.txt 2>&1

Internally you have three "standard" streams: input, output, and error.

  • input you're directing that to c:\backup\sde_04_06_2018.backup
  • output you're directing output to c:\backup\result.txt
  • You need to also redirect error.
  • Thanks Evan. But I just got the same result as before. – Juan Carlos Oropeza Apr 17 '18 at 20:29
  • @JuanCarlosOropeza try that (moving 2>&1 to the end) – Evan Carroll Apr 17 '18 at 20:31
  • 1
    Perfect. Just for feedback. You answer direct to my comment instead of the question. Do you think my question wasn't clear enough? – Juan Carlos Oropeza Apr 17 '18 at 20:39
  • Well, I didn't read properly at first -- so yea, it can always be cleaer. For instance, as it turned out -- it has nothing to do with PostgreSQL, or psql, or restoring a database. But, I can see how that would be very confusing to someone who doesn't understand the standard streams/sysadmin stuff. – Evan Carroll Apr 17 '18 at 20:45
  • It's ok, all good. Sometimes you don't have the information to make it clearer, I can't reasonably expect someone to ask "How do I redirect STDERR on Windows" if you don't yet know how the streams work. ;) – Evan Carroll Apr 17 '18 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.