diff options
author | Ade Lovett <ade@FreeBSD.org> | 2004-11-23 19:15:12 +0000 |
---|---|---|
committer | Ade Lovett <ade@FreeBSD.org> | 2004-11-23 19:15:12 +0000 |
commit | 03e63e3bdbb7e407689c7729c740d54a32bfd7a3 (patch) | |
tree | fd42ebe70af842b5bcd5e9464a31faf2868ed0f1 /databases/postgresql91-server/files/502.pgsql | |
parent | a974bbd8dd5d248923f9f3c059f3cd85e278e2e7 (diff) | |
download | ports-03e63e3bdbb7e407689c7729c740d54a32bfd7a3.tar.gz ports-03e63e3bdbb7e407689c7729c740d54a32bfd7a3.zip |
Another step along the road to the postgresql new world order.
Note that none of these ports are (yet) hooked into the tree,
and will not compile unless you set a specific environmental
variable. This should be warning enough to leave well alone
for now :)
Submitted by: maintainer
Notes
Notes:
svn path=/head/; revision=122238
Diffstat (limited to 'databases/postgresql91-server/files/502.pgsql')
-rw-r--r-- | databases/postgresql91-server/files/502.pgsql | 130 |
1 files changed, 69 insertions, 61 deletions
diff --git a/databases/postgresql91-server/files/502.pgsql b/databases/postgresql91-server/files/502.pgsql index 84cdb9b5ad45..a1cf9ba4f2ee 100644 --- a/databases/postgresql91-server/files/502.pgsql +++ b/databases/postgresql91-server/files/502.pgsql @@ -11,79 +11,87 @@ # 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. + +# 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_vaccum_enable="NO" +daily_pgsql_backup_enable="NO" -DIR=`dirname $0` -progname=`basename $0` -PRG=`cd $DIR; pwd `/$progname +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" -# Run as user pgsql -if [ `id -un` != pgsql ]; then - su -l pgsql -c ${PRG} - exit $? +# 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 -# arguments to pg_dump -PGDUMP_ARGS=${PGDUMP_ARGS:-"-b -F c"} +# allow '~´ in dir name +eval backupdir=${daily_pgsql_backupdir} -# The directory where the backups will reside. -# ${HOME} is pgsql's home directory -PGBACKUPDIR=${PGBACKUPDIR:-${HOME}/backups} +rc=0 -# If you want to keep a history of database backups, set -# PGBACKUP_SAVE_DAYS in ~pgsql/.profile to the number of days. This is -# used as "find ... -mtime +${PGBACKUP_SAVE_DAYS} -delete", see below -PGBACKUP_SAVE_DAYS=${PGBACKUP_SAVE_DAYS:-7} +case "$daily_pgsql_backup_enable" in + [Yy][Ee][Ss]) -# 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 + # 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" + 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=$? -now=`date "+%Y-%m-%dT%H:%M:%S"` -file=${PGBACKUPDIR}/pgglobals_${now} -pg_dumpall -g | gzip -9 > ${file}.gz -for db in ${dbnames}; do - echo -n " $db" - file=${PGBACKUPDIR}/pgdump_${db}_${now} - pg_dump ${PGDUMP_ARGS} -f ${file} ${db} - [ $? -gt 0 ] && rc=3 -done + # 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 + 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 ${backupdir} \( -name 'pgdump_*' -o -name 'pgglobals_*' \) \ + -a -mtime +${daily_pgsql_savedays} -delete + ;; +esac + +case "$daily_pgsql_vacuum_enable" in + [Yy][Ee][Ss]) -# cleaning up old data -find ${PGBACKUPDIR} \( -name 'pgdump_*' -o -name 'pgglobals_*' \) \ - -a -mtime +${PGBACKUP_SAVE_DAYS} -delete + 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 |