From 0c17090552d7b68ae9ddf4a6a270159489f80070 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sat, 28 Sep 2019 19:28:56 +0200 Subject: [PATCH] Move list of clusters to make a base backup of from the script to a conffile --- modules/postgres/manifests/backup_server.pp | 21 +++------- .../manifests/backup_server/globals.pp | 2 +- .../backup_server/register_backup_cluster.pp | 41 +++++++++++-------- .../postgres-make-base-backups.erb | 5 +-- 4 files changed, 33 insertions(+), 36 deletions(-) diff --git a/modules/postgres/manifests/backup_server.pp b/modules/postgres/manifests/backup_server.pp index 41f415a4b..0da5594af 100644 --- a/modules/postgres/manifests/backup_server.pp +++ b/modules/postgres/manifests/backup_server.pp @@ -16,24 +16,15 @@ class postgres::backup_server { #### # Regularly pull base backups # - concat { $postgres::backup_server::globals::make_base_backups: - mode => '0555', + concat { $postgres::backup_server::globals::base_backup_clusters: + ensure_newline => true, } - concat::fragment { 'make-base-backups-header': - target => $postgres::backup_server::globals::make_base_backups, + Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_base_backup |>> + + file { '/usr/local/bin/postgres-make-base-backups': + mode => '0555', content => template('postgres/backup_server/postgres-make-base-backups.erb'), - order => '00', } - Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_base_backup |>> - concat::fragment { 'make-base-backups-tail': - target => $postgres::backup_server::globals::make_base_backups, - content => @(EOTEMPLATE), - # EOF by make-base-backups-tail fragment - EOF - | EOTEMPLATE - order => '99', - } - file { '/etc/cron.d/puppet-postgres-make-base-backups': ensure => absent; } file { '/var/lib/dsa/postgres-make-base-backups': ensure => directory, owner => 'debbackup', diff --git a/modules/postgres/manifests/backup_server/globals.pp b/modules/postgres/manifests/backup_server/globals.pp index 550450487..0dd3d8cc5 100644 --- a/modules/postgres/manifests/backup_server/globals.pp +++ b/modules/postgres/manifests/backup_server/globals.pp @@ -1,8 +1,8 @@ # class postgres::backup_server::globals { - $make_base_backups = '/usr/local/bin/postgres-make-base-backups' $pgpassfile = '/home/debbackup/.pgpass' $sshkeys_sources = '/etc/dsa/postgresql-backup/sshkeys-sources' + $base_backup_clusters = '/etc/dsa/postgresql-backup/base-backup-clusters' $tag_base_backup = "postgresql::server::backup-source-make-base-backup-entry" $tag_source_sshkey = "postgresql::server::backup-source-sshkey" diff --git a/modules/postgres/manifests/backup_server/register_backup_cluster.pp b/modules/postgres/manifests/backup_server/register_backup_cluster.pp index 0fd482cdb..44a1e42d4 100644 --- a/modules/postgres/manifests/backup_server/register_backup_cluster.pp +++ b/modules/postgres/manifests/backup_server/register_backup_cluster.pp @@ -1,12 +1,23 @@ # +# Cause our pg backup servers to run base backups of +# this postgres cluster and add the cluster to the +# monitoring configuration. +# +# @param hostname name of the db server +# @param fqdn fqdn of the db server +# @param pg_port port of the postgres cluster +# @param pg_role replication role username +# @param pg_password password of the replication role +# @param pg_cluster cluster name +# @param pg_version pg version of the cluster define postgres::backup_server::register_backup_cluster ( - $hostname = $::hostname, - $fqdn = $::fqdn, - $pg_port, - $pg_role, - $pg_password, - $pg_cluster, - $pg_version, + String $hostname = $::hostname, + String $fqdn = $::fqdn, + Integer $pg_port, + String $pg_role, + String $pg_password, + String $pg_cluster, + String $pg_version, ) { include postgres::backup_server::globals @@ -18,24 +29,22 @@ define postgres::backup_server::register_backup_cluster ( | EOF tag => $postgres::backup_server::globals::tag_source_pgpassline, } - # - # vittoria.debian.org 5432 debian-backup main 9.6 + # example entry: + # vittoria.debian.org 5432 debian-backup main 9.6 @@concat::fragment { "postgresql::server::backup-source-make-base-backup-entry::$hostname::$pg_port::$pg_role": - target => $postgres::backup_server::globals::make_base_backups, - content => @("EOF"), - ${fqdn} ${pg_port} ${pg_role} ${pg_cluster} ${pg_version} - | EOF tag => $postgres::backup_server::globals::tag_base_backup, + target => $postgres::backup_server::globals::base_backup_clusters, + content => "${::fqdn} ${pg_port} ${pg_role} ${pg_cluster} ${pg_version}", } @@file { "/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/${hostname}-${pg_cluster}.conf": - content => @("EOF"), + content => @("EOF"), --- backups: ${hostname}: ${pg_cluster}: | EOF - tag => $postgres::backup_server::globals::tag_dsa_check_backupp, - notify => Exec['update dsa-check-backuppg-manual.conf'] + tag => $postgres::backup_server::globals::tag_dsa_check_backupp, + notify => Exec['update dsa-check-backuppg-manual.conf'] } } diff --git a/modules/postgres/templates/backup_server/postgres-make-base-backups.erb b/modules/postgres/templates/backup_server/postgres-make-base-backups.erb index 72a93dc63..fc564110d 100755 --- a/modules/postgres/templates/backup_server/postgres-make-base-backups.erb +++ b/modules/postgres/templates/backup_server/postgres-make-base-backups.erb @@ -164,7 +164,4 @@ while read host port username cluster version; do log "Cannot acquire lock on $flagfile, skipping $host:$port $version/$cluster." fi fi -done << EOF -# -# puppet notice: this is just a partial file. The tail EOF comes -# from a different concat fragment +done < '<%= scope['postgres::backup_server::globals::base_backup_clusters'] %> ' -- 2.20.1