library/roles/postgresql: Give the possibility to disable the postgresql backups. Create the list of dbs that need a backup automatically, if one is not provided.

This commit is contained in:
Andrea Dell'Amico 2016-01-11 17:43:50 +01:00
parent a4025969f8
commit 8a23cbc153
3 changed files with 26 additions and 10 deletions

View File

@ -45,18 +45,20 @@ psql_db_user: db_user
psql_db_pwd: "We cannot save the password into the repository. Use another variable and change pgpass.j2 accordingly. Encrypt the file that contains the variable with ansible-vault"
postgres_install_gis_extensions: False
postgres_gis_version: 2.1
postgres_gis_pkgs:
- postgresql-'{{ psql_version }}'-postgis-'{{ postgres_gis_version }}'
pg_backup_enabled: True
pg_backup_logdir: /var/log/postgresql
pg_backup_bin: /usr/local/sbin/postgresql-backup
pg_backup_pgdump_bin: /usr/bin/pg_dump
pg_backup_retain_copies: 15
pg_backup_build_db_list: "no"
pg_backup_db_list: '{{ psql_db_name}}'
# Dynamically created from psql_db_data if pg_backup_db_list is not set
#pg_backup_db_list: '{{ psql_db_name}}'
pg_backup_destdir: /var/lib/pgsql/backups
pg_backup_logdir: /var/log/postgresql
pg_backup_logfile: '{{ pg_backup_logdir }}/postgresql-backup.log'

View File

@ -3,6 +3,7 @@
if [ -f /etc/default/pg_backup ] ; then
. /etc/default/pg_backup
else
PG_BACKUP_ENABLED=True
PG_SERVICE=postgresql
USE_NAGIOS=no
LOG_DIR=/var/log/postgresql
@ -14,16 +15,20 @@ export PATH="/sbin:/usr/sbin:/usr/local/sbin:$PATH"
PG_SVC=$( service $PG_SERVICE status >/dev/null )
PG_RUNNING=$?
if [ ! -d $LOG_DIR ] ; then
mkdir -p $LOG_DIR
fi
if [ "$PG_RUNNING" -ne "0" -a "$PG_RUNNING" -ne "3" ] ; then
echo "postgresql not running" > $LOG_FILE
exit 1
if [ '$PG_BACKUP_ENABLED' == 'True' ] ; then
if [ "$PG_RUNNING" -ne "0" -a "$PG_RUNNING" -ne "3" ] ; then
echo "The postgresql service is not running" > $LOG_FILE
exit 1
else
if [ ! -d $LOG_DIR ] ; then
mkdir -p $LOG_DIR
fi
$PG_BCK_BIN > $LOG_FILE 2>&1
fi
else
$PG_BCK_BIN > $LOG_FILE 2>&1
echo "Postgresql backups administratively disabled" > $LOG_FILE
fi
if [ "${USE_NAGIOS}" == "yes" ] ; then
N_LOGDIR=/var/log/nagios-checks
if [ ! -d $N_LOGDIR ] ; then

View File

@ -1,13 +1,22 @@
PG_SERVICE=postgresql
PG_BACKUP_ENABLED={{ pg_backup_enabled }}
PG_VERSION={{ psql_version }}
PG_DUMP_BIN={{ pg_backup_pgdump_bin }}
PG_BCK_BIN={{ pg_backup_bin }}
{% if pg_backup_enabled }}
USE_NAGIOS={{ pg_backup_use_nagios }}
{% else %}
USE_NAGIOS=no
{% endif %}
LOG_DIR={{ pg_backup_logdir }}
LOG_FILE={{ pg_backup_logfile}}
N_DAYS_TO_SPARE={{ pg_backup_retain_copies }}
BUILD_DBLIST={{ pg_backup_build_db_list }}
{% if pg_backup_db_list is defined %}
DB_LIST="{{ pg_backup_db_list }}"
{% else %}
DB_LIST="{% for db in psql_db_data %}{{ db.name }} {% endfor %}"
{% endif %}
PG_USE_AUTH={{ pg_backup_use_auth }}
PG_PASS_FILE={{ pg_backup_pass_file }}
BACKUPDIR={{ pg_backup_destdir }}