freebsd-ports/databases/postgresql82-server/files/502.pgsql
Palle Girgensohn dde08c696b Say hello to postgresql-8.0. Some of the highlights of the new version
are savepoints (within transactions), point-in-time recovery and
tablespaces. Check out the release notes and the shiny new
PostgreSQL.org website at:

http://www.PostgreSQL.org/docs/8.0/static/release.html#RELEASE-8-0

The port uses the new postgresql ports' layout and is split into a
server and a client part. The following knobs can be used by ports
depending on PostgreSQL:

# USE_PGSQL     - Add PostgreSQL client dependency.
#                 If no version is given (by the maintainer via the port or
#                 by the user via defined variable), try to find the
#                 currently installed version.  Fall back to default if
#                 necessary (PostgreSQL-7.4 = 74).
# DEFAULT_PGSQL_VER
#               - PostgreSQL default version. Can be overridden within a port.
#                 Default: 74.
# WANT_PGSQL_VER
#               - Maintainer can set an arbitrary version of PostgreSQL by
#                 using it.
# BROKEN_WITH_PGSQL
#               - This variable can be defined if the ports doesn't support
#                 one or more versions of PostgreSQL.

PR:		75344
Approved by:	portmgr@ (kris), ade & sean (mentors)
2005-01-31 00:36:16 +00:00

97 lines
2.4 KiB
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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@pingpong.net>
#
# In public domain, do what you like with it,
# and use it at your own risk... :)
#
# Define these variables in either /etc/periodic.conf or
# /etc/periodic.conf.local to override the default values.
#
# daily_pgsql_backup_enable="YES" # do backup
# daily_pgsql_vacuum_enable="YES" # do vacuum
daily_pgsql_vacuum_enable="YES"
daily_pgsql_backup_enable="NO"
daily_pgsql_vacuum_args="-z"
daily_pgsql_pgdump_args="-b -F c"
# backupdir is relative to ~pgsql home directory unless it begins with a slash:
daily_pgsql_backupdir="~pgsql/backups"
daily_pgsql_savedays="7"
# If there is a global system configuration file, suck it in.
#
if [ -r /etc/defaults/periodic.conf ]
then
. /etc/defaults/periodic.conf
source_periodic_confs
fi
# allow '~´ in dir name
eval backupdir=${daily_pgsql_backupdir}
rc=0
case "$daily_pgsql_backup_enable" in
[Yy][Ee][Ss])
# daily_pgsql_backupdir 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 ${backupdir} ] ; then
echo Creating ${backupdir}
mkdir ${backupdir}; chmod 700 ${backupdir}; chown pgsql ${backupdir}
fi
echo
echo "PostgreSQL maintenance"
# Protect the data
umask 077
dbnames=`su -l pgsql -c "psql -q -t -A -d template1 -c SELECT\ datname\ FROM\ pg_database\ WHERE\ datname!=\'template0\'"`
rc=$?
now=`date "+%Y-%m-%dT%H:%M:%S"`
file=${daily_pgsql_backupdir}/pgglobals_${now}
su -l pgsql -c "pg_dumpall -g | gzip -9 > ${file}.gz"
for db in ${dbnames}; do
echo -n " $db"
file=${backupdir}/pgdump_${db}_${now}
su -l pgsql -c "pg_dump ${daily_pgsql_pgdump_args} -f ${file} ${db}"
[ $? -gt 0 ] && rc=3
done
if [ $rc -gt 0 ]; then
echo
echo "Errors were reported during backup."
fi
# cleaning up old data
find ${backupdir} \( -name 'pgdump_*' -o -name 'pgglobals_*' \) \
-a -mtime +${daily_pgsql_savedays} -delete
;;
esac
case "$daily_pgsql_vacuum_enable" in
[Yy][Ee][Ss])
echo
echo "vacuuming..."
su -l pgsql -c "vacuumdb -a -q ${daily_pgsql_vacuum_args}"
if [ $? -gt 0 ]
then
echo
echo "Errors were reported during vacuum."
rc=3
fi
;;
esac
exit $rc