0

How to create a backup of an POSTGRES DB using bash?

3 Answers 3

5
pg_dump -U some_user_name -f dump.file -Fc database_name

That's all.

If you need to authenticate with password - use pgpass file.

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

Comments

0

Use pg_dump.

1 Comment

I have difficulties including the username and password with pg_dump
0

Ideally you should add an scheduled job to crontab to be executed daily. The following will create a gzipped sql file with timestamp. SQL dumps otherwise could be very big.

pg_dump database_name | gzip -c > ~/backup/postgres/database_name-`/bin/date +%Y%m%d-%H%M`.sql.gz

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.