postgresql: Added postgresql::server::backup class for database backups.

This commit is contained in:
Timo Makinen 2014-11-08 15:43:59 +02:00
parent 183147594a
commit 39a60084c4
2 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,35 @@
#!/bin/sh
umask 077
if [ `whoami` != postgres ]; then
echo "ERR: Script needs to be run as postgres user" 1>&2
exit 1
fi
DESTDIR="<%= @datadir %>"
MAXAGE="<%= @maxage %>"
DATE=`date "+%Y-%m-%d"`
if [ ! -d ${DESTDIR} ]; then
echo "ERR: PostgreSQL backup directory [${DESTDIR}] does not exist" 1>&2
exit 1
fi
cd ${DESTDIR} && {
find . -xdev -mindepth 2 -maxdepth 2 -type f -mtime +7 -execdir rm -f -- {} \;
find . -xdev -depth -mindepth 1 -maxdepth 1 -type d -empty -execdir rmdir -- {} \;
}
DESTDIR=${DESTDIR}/${DATE}
mkdir -p ${DESTDIR}
for db in `psql -l -t | sed -n 's/^ \([^ ]\+\) .*/\1/p'`; do
case ${db} in
template*)
continue
;;
esac
pg_dump ${db} | gzip > ${DESTDIR}/${db}.${DATE}.gz
done