nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Postgres backup

This is a discussion on Postgres backup within the Databases servers forums, part of the Mastering Servers category; Hai, How do I make a backup under postgres database server? Under mysql I can use mysqldump.. what about pgsql ...


Go Back   nixCraft Linux Forum > Mastering Servers > Databases servers

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 01-03-2007, 06:45 PM
Member
User
 
Join Date: Feb 2005
Posts: 66
Rep Power: 0
chiku
Default Postgres backup

Hai,

How do I make a backup under postgres database server? Under mysql I can use mysqldump.. what about pgsql ??? any idea what command i need to use. Also specify script if possible.

TIA
__________________
There's no place like 127.0.0.1
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-03-2007, 07:31 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
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.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #3 (permalink)  
Old 01-03-2007, 10:43 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,060
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Also see Howto Backup PostgreSQL Databases for more info about commands.
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Postgres idle connections kasimani Databases servers 1 05-14-2007 06:58 PM
Postgres vacuumdb usage kasimani Databases servers 2 03-06-2007 08:30 AM


All times are GMT +5.5. The time now is 03:13 AM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36