[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cobalt-users] script to dump postgresql databases
- Subject: [cobalt-users] script to dump postgresql databases
- From: Reinoud van Leeuwen <rvanleeuwen@xxxxxxxxxxxx>
- Date: Fri Mar 2 03:33:14 2001
- List-id: Mailing list for users to share thoughts on Cobalt products. <cobalt-users.list.cobalt.com>
I have not yet seen a script to dump all postgresql databases so I made one.
It might be usefull for other people too (backing up a running database is
usually not guaranteed to work, and this solution keeps a few versions
online as well). My script is located in ~root and cronned at 1 AM each
night (before the tape backup starts)
#!/bin/sh
##########################################
# dumpdbs - dump all PostgreSQL databases
# Reinoud van Leeuwen (reinoud.v@xxxxxxxxxxxxx)
#
# $Revision: 1.1 $
#
# $Log: dumpdbs,v $
# Revision 1.1 2001/03/02 11:11:15 root
# Initial revision
#
#
##########################################
DESTDIR=/home/sites/home/users/admin/postgresqldumps
DAYSTOKEEP=14
DUMPCMD=/usr/bin/pg_dumpall
##########################################################################
# test for existence of target directory and create it if it does not exist
##########################################################################
#
if [ ! -d $DESTDIR ]; then
mkdir -p $DESTDIR
chown postgres:admin $DESTDIR
fi
##########################################################################
# remove dumps older than $DAYSTOKEEP
##########################################################################
find $DESTDIR -mtime $DAYSTOKEEP -exec rm {} \;
##########################################################################
# make dump of all databases to a file with a datestamp in the filename
##########################################################################
su postgres -c "$DUMPCMD > $DESTDIR/`date +%Y%m%d`.pg_dumpall"