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.
Best Answer
If you're asking how do you put the error to the "result file" too, you need to redirect
STDERR
as well asSTDOUT
or directSTDERR
toSTDOUT
with2>&1
Internally you have three "standard" streams: input, output, and error.
input
you're directing that toc:\backup\sde_04_06_2018.backup
output
you're directing output toc:\backup\result.txt
error
.