1

I have a database server without much disk space, so I took a backup of the entire db (let's just call it redblue) and saved it locally using the following command (I don't have pg running on my computer):

ssh [email protected] "pg_dump -U postgres redblue -h localhost " \
 >> db_backup_redblue.sql

I'd like to now restore it to another server (1.2.3.4) which contains an older version of "redblue" database - however wanted to ask if this is right before I try it:

ssh [email protected] "pg_restore -U postgres -C redblue" \
<< db_backup_redblue.sql

I wasn't sure if I need to do -C with the name of the db or not?

Will the above command overwrite/restore the remote database with the file I have locally?

Thanks!

1

2 Answers 2

2

No, that will do nothing good.

You have to start pg_restore on the machine where the dump is. Actually, since this is a plain format dump, you have to use psql rather than pg_restore:

psql -h 1.2.3.4 -U postgres -d redblue -f db_backup_redblue.sql

That requires that there is already an empty database redblue on the target system.

If you want to replace an existing database, you have to use the --clean and --create options with pg_dump.

If you want to use SSL, you'll have to configure the PostgreSQL server to accept SSL connections, see the documentation.

I'd recommend the “custom” format of pg_dump.

Sign up to request clarification or add additional context in comments.

Comments

1

Of course, you can do this :) Assuming you use ssh keys to authorize user from source host to destination host.

On the source host you do the pg_dump, then pipe through ssh to destination host like this:

pg_dump -C nextcloud | ssh -i .ssh/pg_nextcloud_key [email protected] psql -d template1

Hope that helps ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.