Postgres – Automate DB Backups

Automate DB Backups for your Postgres DB. This can be implemented by storing the DB Account password in a .pgpass file under the user’s home directory. The contents of the file look like:

localhost:5432:primarydb:root:RootPassword
localhost:5432:other_db:otheruser:Other_Password

Once the pgpass file is setup – backups is just as simple as

pg_dump -h localhost -U otheruser -w other_db > other_db_backup.sql

-w indicates that the password prompt is not required. The system will look for the password in the user’s pgpass file.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s