postgresql: Added postgresql::server::backup class for database backups.
This commit is contained in:
parent
183147594a
commit
39a60084c4
2 changed files with 76 additions and 0 deletions
35
postgresql/templates/pgsql-backup.erb
Executable file
35
postgresql/templates/pgsql-backup.erb
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue