I love Free Software!

Pages

Funny Quotes to Think

When you say "I wrote a program that crashed Windows", people just stare at You blankly and say "Hey, I got those with the system, for free"

-Torvalds, Linus(1995-03-08)-

Monday, December 7, 2009

How to backup postgres database without issuing password

pq_dump command does not accept any password as argument. Here I am adding a small script which will
help you to take backup of your postgres database

#!/bin/bash

TODAY=`date +%b%d%Y`
DST=/path/to/put/backup

export PGPASSWORD=password #Adding postgres password in script
find $DST/* -maxdepth 0 -type f -mtime +40 -exec rm -v '{}' \;
pg_dump -U dbuser -h localhost dbname | bzip2 -c > $DST/pg.db.$TODAY.bz2

1 comment: