#!/bin/sh
# save the old databases
dump=/var/tmp/db.out.gz
if [ -x /usr/bin/pg_dumpall ]; then
  if [ ! `ps x 2>&1 | grep postmaster` ]; then
    echo "WARNING: could not save old postgres database"
    echo "starting postmaster and run pg_dumpall"
    /usr/bin/pg_ctl -l /var/log/postgresql.log start
  fi
  /usr/bin/pg_dumpall | gzip -c > $dump
  /usr/bin/pg_ctl stop
fi
