aboutsummaryrefslogtreecommitdiff
path: root/databases/postgresql74-server/files/502.pgsql
diff options
context:
space:
mode:
Diffstat (limited to 'databases/postgresql74-server/files/502.pgsql')
-rw-r--r--databases/postgresql74-server/files/502.pgsql72
1 files changed, 42 insertions, 30 deletions
diff --git a/databases/postgresql74-server/files/502.pgsql b/databases/postgresql74-server/files/502.pgsql
index 160de10370e0..32d473826f40 100644
--- a/databases/postgresql74-server/files/502.pgsql
+++ b/databases/postgresql74-server/files/502.pgsql
@@ -11,6 +11,20 @@
# In public domain, do what you like with it,
# and use it at your own risk... :)
#
+############################
+
+# arguments to pg_dump
+PGDUMP_ARGS="-b -F c"
+
+# the directory where the backups will reside
+# ${HOME} is pgsql's home directory
+PGBACKUPDIR=${HOME}/backups
+
+# some data is amazingly more compressed with bzip2, esp. blobs, it seems
+# if your're short on diskspace, give it a try and set USEBZIP=yes
+USEBZIP=no
+
+############################
DIR=`dirname $0`
progname=`basename $0`
@@ -19,58 +33,56 @@ PRG=`cd $DIR; pwd `/$progname
# Run as user pgsql
if [ `id -un` != pgsql ]; then
su -l pgsql -c ${PRG}
- exit 0
+ exit $?
+fi
+
+if [ X${USEBZIP} = Xyes ]; then
+ BZIP=`which bzip2 || echo true`
+else
+ BZIP=true
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..."
+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
+dbnames=`psql -q -t -A -d template1 -c "SELECT datname FROM pg_database WHERE datname != 'template0'"`
+rc=$?
+for db in ${dbnames}; do
+ echo -n " $db"
+ file=${PGBACKUPDIR}/pgdump_${db}_`date "+%Y%m%d"`
+ pg_dump ${PGDUMP_ARGS} -d $db -f ${file}
+ [ $? -gt 0 ] && rc=3
+ ${BZIP} ${file}
done
-if [ -s "${PGERRALL}" ]
-then
- echo
- echo 'Something went wrong!'
+if [ $rc -gt 0 ]; then
echo
- echo `cat ${PGERRALL}`
- rc=3
+ echo "Errors were reported during backup."
fi
-rm ${PGERRALL}
echo
+echo "vacuuming..."
+vacuumdb -a -z -q
+if [ $? -gt 0 ]
+then
+ echo
+ echo "Errors were reported vacuum."
+ rc=3
+fi
+# cleaning up old data
find ${PGBACKUPDIR} \( -name 'pgdump_*'.${GZIPEXT} -o -name 'pgdumpall_*'.${GZIPEXT} \) \
-a -atime +7 -delete
+
exit $rc