97 lines
2.9 KiB
Text
97 lines
2.9 KiB
Text
|
#!/bin/sh
|
||
|
#
|
||
|
# 2013-2015 ungleich GmbH (cdist at ungleich.ch)
|
||
|
#
|
||
|
# This file is part of cdist.
|
||
|
#
|
||
|
# cdist is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation, either version 3 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# cdist is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||
|
#
|
||
|
|
||
|
user="$(cat "$__object/parameter/user")"
|
||
|
|
||
|
os=$(cat $__global/explorer/os)
|
||
|
osversion=$(cat "$__global/explorer/os_version")
|
||
|
|
||
|
case "$os" in
|
||
|
debian)
|
||
|
postgres_lib=libpq-dev
|
||
|
|
||
|
case $osversion in
|
||
|
6*)
|
||
|
postgres_version=8.4
|
||
|
;;
|
||
|
7*)
|
||
|
postgres_version=9.1
|
||
|
;;
|
||
|
8*)
|
||
|
postgres_version=9.4
|
||
|
;;
|
||
|
*)
|
||
|
echo "Unsupported OS Version: $osversion" >&2
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
;;
|
||
|
*)
|
||
|
echo "Unsupported OS: $os" >&2
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
# Allow version override
|
||
|
if [ -f "$__object/parameter/version" ]; then
|
||
|
postgres_version=$(cat "$__object/parameter/version")
|
||
|
fi
|
||
|
|
||
|
postgres_server="postgresql-${postgres_version}"
|
||
|
|
||
|
################################################################################
|
||
|
# Configure PostgreSQL
|
||
|
#
|
||
|
|
||
|
require="__package/$postgres_server" __postgres_role "$user" \
|
||
|
--state present --login --createdb
|
||
|
|
||
|
__package "$postgres_server" --state present
|
||
|
|
||
|
require="__package/$postgres_server" __start_on_boot postgresql
|
||
|
|
||
|
################################################################################
|
||
|
# Create backups
|
||
|
#
|
||
|
|
||
|
if [ ! -f "$__object/parameter/no-backup" ]; then
|
||
|
require="__package/$postgres_server" __directory /var/backups/postgres \
|
||
|
--owner postgres --group postgres
|
||
|
|
||
|
require="__package/$postgres_server __directory/var/backups/postgres" __cron \
|
||
|
pg_dumpall_under_day \
|
||
|
--user postgres \
|
||
|
--hour 8,9,10,11,12,14,15,16,17,18 --minute 0 \
|
||
|
--command 'nice pg_dumpall | gzip > /var/backups/postgres/dumpall-$(date +\%H\%M).sql.gz'
|
||
|
|
||
|
require="__package/$postgres_server __directory/var/backups/postgres" __cron \
|
||
|
pg_dumpall_archive \
|
||
|
--user postgres \
|
||
|
--hour 2 --minute 0 \
|
||
|
--command 'nice pg_dumpall | gzip > /var/backups/postgres/dumpall-$(date +\%Y\%m\%d-\%H\%M).sql.gz'
|
||
|
|
||
|
# Delete local backups after 7 days
|
||
|
require="__package/$postgres_server __directory/var/backups/postgres" __cron \
|
||
|
pg_dump_cleanup \
|
||
|
--user postgres \
|
||
|
--hour 1 --minute 0 \
|
||
|
--command 'find /var/backups/postgres -type f -mtime +7 -delete'
|
||
|
fi
|