Thread: Postgres backup

View Single Post
  #2 (permalink)  
Old 3rd January 2007, 06:31 PM
rockdalinux's Avatar
rockdalinux rockdalinux is offline
Is that all you got?
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 823
Thanks: 21
Thanked 37 Times in 32 Posts
Rep Power: 12
rockdalinux is a splendid one to beholdrockdalinux is a splendid one to beholdrockdalinux is a splendid one to beholdrockdalinux is a splendid one to beholdrockdalinux is a splendid one to beholdrockdalinux is a splendid one to behold
Default

Here is my postgres (pgsql) backup script:

Code:
#!/bin/sh
# Bak dump dir - Change me
BACKUP="/backup"
# get list of dbs
PGDBS=$(psql -h localhost -U postgres -q -c "\l" | sed -n 4,/\eof/p | grep -v rows\) | awk {'print $1'})

for d in $PGDBS; do
        NOW=`date '+%T %x'`
        vacuumdb -z -h localhost -U postgres $d
        pg_dump $d -h localhost | gzip > "$BACKUP/postgresql-$d-$NOW.gz"
done
Run script as postgres or root user. Cron job:
Code:
03 05 * * * /path/to/pgsql.backup.sh > /dev/null 2>&1
__________________
Rocky Jr.
What's wrong? I hope I am not making you uncomfortable...

Never send a boy to do a mans job.
Reply With Quote