ports/databases/postgresql72/files/502.pgsql
Sean Chittenden d87a4a6578 Bow to the masses who have complained bitterly about not being able to
upgrade to the PostgreSQL 7.3 series and provide an update to the 7.2
series, 7.2.4.  :~]  This port _will_ be removed and should EOL'ed in
about 6 months time.  Since there is no future for these bits, ignore their
heritage commit an orphan for the 7 series.  See the postgresql7 port for
future and past bits.  This port is only intended to serve as a means of
postponing an inevitable upgrade to recent release.

DBAs, please plan and begin upgrading to 7.3.X, the grass really is greener.

Release notes:
http://developer.postgresql.org/docs/postgres/release-7-2-4.html

PR:		ports/48025
Submitted by:	Palle Girgensohn <girgen@pingpong.net>
2003-02-07 11:00:47 +00:00

83 lines
2 KiB
PL/PgSQL

#!/bin/sh
#
# $FreeBSD$
#
# Maintenance shell script to vacuum and backup database
# Put this in /usr/local/etc/periodic/daily, and it will be run
# every night
#
# Written by Palle Girgensohn <girgen@partitur.se>
#
# In public domain, do what you like with it,
# and use it at your own risk... :)
#
######################################################################
#
# If you like to tweak the settings of the variables PGBACKUPDIR and
# PGDUMP_ARGS, you should preferably set them in ~pgsql/.profile.
# If set there, that setting will override the defaults here.
#
######################################################################
DIR=`dirname $0`
progname=`basename $0`
PRG=`cd $DIR; pwd `/$progname
# Run as user pgsql
if [ `id -un` != pgsql ]; then
su -l pgsql -c ${PRG}
exit $?
fi
# arguments to pg_dump
PGDUMP_ARGS=${PGDUMP_ARGS:-"-b -F c"}
# The directory where the backups will reside.
# ${HOME} is pgsql's home directory
#
PGBACKUPDIR=${PGBACKUPDIR:-${HOME}/backups}
# PGBACKUPDIR must be writeable by user pgsql
# ~pgsql is just that under normal circumstances,
# but this might not be where you want the backups...
if [ ! -d ${PGBACKUPDIR} ] ; then
echo Creating ${PGBACKUPDIR}
mkdir ${PGBACKUPDIR}
chmod 700 ${PGBACKUPDIR}
fi
echo
echo "PostgreSQL maintenance"
# Protect the data
umask 077
dbnames=`psql -q -t -A -d template1 -c "SELECT datname FROM pg_database WHERE datname != 'template0'"`
rc=$?
file=${PGBACKUPDIR}/pgglobals_`date "+%Y%m%d"`
pg_dumpall -g | gzip -9 > ${file}.gz
for db in ${dbnames}; do
echo -n " $db"
file=${PGBACKUPDIR}/pgdump_${db}_`date "+%Y%m%d"`
pg_dump ${PGDUMP_ARGS} -f ${file} ${db}
[ $? -gt 0 ] && rc=3
done
if [ $rc -gt 0 ]; then
echo
echo "Errors were reported during backup."
fi
echo
echo "vacuuming..."
vacuumdb -a -z -q
if [ $? -gt 0 ]
then
echo
echo "Errors were reported during vacuum."
rc=3
fi
# cleaning up old data
find ${PGBACKUPDIR} -name 'pgdump_*' -a -atime +7 -delete
exit $rc