Elitmiar
Elitmiar

Reputation: 36839

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

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

Upvotes: 0

Views: 533

Answers (3)

Maksym Kozlenko
Maksym Kozlenko

Reputation: 10363

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

Upvotes: 0

user80168
user80168

Reputation:

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.

Upvotes: 5

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181280

Use pg_dump.

Upvotes: 0

Related Questions