diff options
author | Vanilla I. Shu <vanilla@FreeBSD.org> | 2002-02-19 08:23:22 +0000 |
---|---|---|
committer | Vanilla I. Shu <vanilla@FreeBSD.org> | 2002-02-19 08:23:22 +0000 |
commit | 0c0bcdc10ba6c2d0bbf6c831f5bc05a32470a2e7 (patch) | |
tree | e2c20382071c1aac790898564dea14a5b332a404 /databases/postgresql81-server/files/502.pgsql | |
parent | APP_TITLE was set twice. (diff) |
Upgrade to 7.2, and spilit into several ports.
PR: ports/34855
Submitted by: maintainer.
Notes
Notes:
svn path=/head/; revision=54887
Diffstat (limited to 'databases/postgresql81-server/files/502.pgsql')
-rw-r--r-- | databases/postgresql81-server/files/502.pgsql | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/databases/postgresql81-server/files/502.pgsql b/databases/postgresql81-server/files/502.pgsql new file mode 100644 index 000000000000..160de10370e0 --- /dev/null +++ b/databases/postgresql81-server/files/502.pgsql @@ -0,0 +1,76 @@ +#!/bin/sh +# +# $Id: 502.pgsql.in,v 1.17 2001/10/29 10:12:32 henrik Exp $ +# +# 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... :) +# + +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 0 +fi + +# PGBACKUPDIR must be writeable by user pgsql +# ~pgsql is just that under normal circumstances, +# but this might not be where you want the backups... +PGBACKUPDIR=${HOME}/backups +if [ ! -d ${PGBACKUPDIR} ] ; then + echo Creating ${PGBACKUPDIR} + mkdir ${PGBACKUPDIR} + chmod 700 ${PGBACKUPDIR} +fi + +PGLOGDIR=/var/log/pgsql +PGDIR=`cd ${PGDATA}/../ && pwd` + +GZIP=/usr/bin/bzip2 +GZIPEXT=bz2 + +echo +echo "PostgreSQL maintenance..." + +# Protect the data +umask 077 + +dbname=`${PGBINDIR}/psql -q -t -A -d template1 -c "SELECT datname FROM pg_database WHERE datname != 'template0'"` + +rc=0 + +echo -n "ALL" +PGERRALL=/tmp/PGERRALL.$$ + +${PGBINDIR}/pg_dumpall 2> $PGERRALL | ${GZIP} > ${PGBACKUPDIR}/pgdumpall_`date "+%Y%m%d"`.${GZIPEXT} + +for i in ${dbname}; do + echo -n " $i" + ${PGBINDIR}/pg_dump $i 2>> $PGERRALL | ${GZIP} > ${PGBACKUPDIR}/pgdump_${i}_`date "+%Y%m%d"`.${GZIPEXT} + ${PGBINDIR}/vacuumdb --quiet --analyze $i || rc=3 +done + +if [ -s "${PGERRALL}" ] +then + echo + echo 'Something went wrong!' + echo + echo `cat ${PGERRALL}` + rc=3 +fi +rm ${PGERRALL} + +echo + +find ${PGBACKUPDIR} \( -name 'pgdump_*'.${GZIPEXT} -o -name 'pgdumpall_*'.${GZIPEXT} \) \ + -a -atime +7 -delete +exit $rc |