2015-05-11 18:42:31 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2019-01-21 15:50:33 +00:00
|
|
|
# 2013-2019 ungleich glarus ag (cdist at ungleich.ch)
|
2015-05-11 18:42:31 +00:00
|
|
|
#
|
|
|
|
# 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
|
2018-12-24 18:05:51 +00:00
|
|
|
debian|devuan)
|
2015-05-11 18:42:31 +00:00
|
|
|
postgres_lib=libpq-dev
|
|
|
|
|
|
|
|
case $osversion in
|
|
|
|
6*)
|
|
|
|
postgres_version=8.4
|
|
|
|
;;
|
|
|
|
7*)
|
|
|
|
postgres_version=9.1
|
|
|
|
;;
|
|
|
|
8*)
|
|
|
|
postgres_version=9.4
|
|
|
|
;;
|
2018-12-24 18:05:51 +00:00
|
|
|
9*|ascii/ceres|ascii)
|
|
|
|
postgres_version=9.6
|
|
|
|
;;
|
2020-01-14 21:40:51 +00:00
|
|
|
11*|beowulf/ceres|beowulf)
|
|
|
|
postgres_version=11
|
|
|
|
;;
|
2015-05-11 18:42:31 +00:00
|
|
|
*)
|
|
|
|
echo "Unsupported OS Version: $osversion" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2019-09-28 06:54:10 +00:00
|
|
|
|
|
|
|
# Allow version override
|
|
|
|
if [ -f "$__object/parameter/version" ]; then
|
|
|
|
postgres_version=$(cat "$__object/parameter/version")
|
|
|
|
fi
|
|
|
|
|
|
|
|
postgres_server="postgresql-${postgres_version}"
|
|
|
|
|
|
|
|
;;
|
|
|
|
alpine)
|
|
|
|
postgres_lib="postgresql-dev"
|
|
|
|
postgres_server="postgresql"
|
2015-05-11 18:42:31 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unsupported OS: $os" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2019-09-28 06:54:10 +00:00
|
|
|
__package "$postgres_server" --state present
|
|
|
|
__package "$postgres_lib" --state present
|
2015-05-11 18:42:31 +00:00
|
|
|
|
2019-09-28 06:54:10 +00:00
|
|
|
require="__package/$postgres_server __package/$postgres_lib" __process postgres --start "service postgresql start"
|
2015-05-11 18:42:31 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Configure PostgreSQL
|
|
|
|
#
|
2019-09-28 06:54:10 +00:00
|
|
|
require="__process/postgres" __postgres_role "$user" \
|
|
|
|
--state present --login --createdb --superuser
|
2015-05-11 18:42:31 +00:00
|
|
|
|
2019-09-28 06:54:10 +00:00
|
|
|
require="__postgres_role/$user" __postgres_database \
|
2015-05-14 09:48:55 +00:00
|
|
|
"$user" --state present --owner "$user"
|
|
|
|
|
2015-05-11 18:42:31 +00:00
|
|
|
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 \
|
2019-09-28 06:54:10 +00:00
|
|
|
--owner postgres --group postgres --parents
|
2015-05-11 18:42:31 +00:00
|
|
|
|
|
|
|
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 \
|
2019-09-28 06:54:10 +00:00
|
|
|
--command 'nice pg_dumpall -U postgres | gzip > /var/backups/postgres/dumpall-$(date +\%H\%M).sql.gz'
|
2015-05-11 18:42:31 +00:00
|
|
|
|
|
|
|
require="__package/$postgres_server __directory/var/backups/postgres" __cron \
|
|
|
|
pg_dumpall_archive \
|
|
|
|
--user postgres \
|
|
|
|
--hour 2 --minute 0 \
|
2019-09-28 06:54:10 +00:00
|
|
|
--command 'nice pg_dumpall -U postgres | gzip > /var/backups/postgres/dumpall-$(date +\%Y\%m\%d-\%H\%M).sql.gz'
|
2015-05-11 18:42:31 +00:00
|
|
|
|
|
|
|
# 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
|