3

How can I do this in one step?

Download backup command:

curl http://s3.aws.com/backup.sql

Restore backup command:

sudo -u postgres psql <PIPE-THE-OUTPUT-OF-PREVIOUS-COMMAND>

3 Answers 3

7

If both command are working, you should try

curl -s http://s3.aws.com/backup.sql | sudo -u postgres psql
2

I know this is an old question, but I just stumbled upon during a search (it was the top of the results) and it does not look like any of the answers are correct according to the postgres manual.

The manual suggests passing the -f - as an option to psql and then piping over stdin what ever you want. Quoting the manual for 9.4:

If filename is - (hyphen), then standard input is read until an EOF indication or \q meta-command. Note however that Readline is not used in this case (much as if -n had been specified).

Using this option is subtly different from writing psql < filename. In general, both will do what you expect, but using -f enables some nice features such as error messages with line numbers.

1

Yet another way:

sudo -u postgres psql --file <(curl -s http://s3.aws.com/backup.sql)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .