2 class postgres::backup_server::globals {
3 $make_base_backups = '/usr/local/bin/postgres-make-base-backups'
4 $pgpassfile = '/home/debbackup/.pgpass'
5 $sshkeys_sources = '/etc/dsa/postgresql-backup/sshkeys-sources'
7 $tag_base_backup = "postgresql::server::backup-source-make-base-backup-entry"
8 $tag_source_sshkey = "postgresql::server::backup-source-sshkey"
9 $tag_source_pgpassline = "postgresql::server::backup-source-pgpassline"
10 $tag_dsa_check_backupp = "postgresql::server::backup-dsa-check-backuppg"
13 class postgres::backup_server {
14 include postgres::backup_server::globals
17 # Regularly pull base backups
19 ensure_packages ( "postgresql-client-9.1", { ensure => 'installed' })
20 ensure_packages ( "postgresql-client-9.4", { ensure => 'installed' })
22 concat { $postgres::backup_server::globals::make_base_backups:
25 concat::fragment { 'make-base-backups-header':
26 target => $postgres::backup_server::globals::make_base_backups,
27 content => template('postgres/backup_server/postgres-make-base-backups.erb'),
30 Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_base_backup |>>
31 concat::fragment { 'make-base-backups-tail':
32 target => $postgres::backup_server::globals::make_base_backups,
33 content => @(EOTEMPLATE),
34 # EOF by make-base-backups-tail fragment
39 file { '/etc/cron.d/puppet-postgres-make-base-backups':
42 if $::hostname in [backuphost] {
43 concat::fragment { 'dsa-puppet-stuff--porterbox-chroot-update':
44 target => '/etc/cron.d/dsa-puppet-stuff',
46 20 1 * * 0 debbackup chronic ${$postgres::backup_server::globals::make_base_backups}
50 concat::fragment { 'dsa-puppet-stuff--porterbox-chroot-update':
51 target => '/etc/cron.d/dsa-puppet-stuff',
53 20 0 * * 6 debbackup chronic ${$postgres::backup_server::globals::make_base_backups}
59 # Maintain authorized_keys file on backup servers for WAL shipping
61 # do not let other hosts directly build our authorized_keys file,
62 # instead go via a script that somewhat validates intput
63 file { '/etc/dsa/postgresql-backup':
64 ensure => 'directory',
66 file { '/usr/local/bin/postgres-make-backup-sshauthkeys':
67 content => template('postgres/backup_server/postgres-make-backup-sshauthkeys.erb'),
69 notify => Exec['postgres-make-backup-sshauthkeys'],
71 file { '/etc/dsa/postgresql-backup/sshkeys-manual':
72 content => template('postgres/backup_server/sshkeys-manual.erb'),
73 notify => Exec['postgres-make-backup-sshauthkeys'],
75 concat { $postgres::backup_server::globals::sshkeys_sources:
76 notify => Exec['postgres-make-backup-sshauthkeys'],
78 concat::fragment { 'postgresql-backup/source-sshkeys-header':
79 target => $postgres::backup_server::globals::sshkeys_sources ,
81 # <name> <ip addresses> <key>
85 Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_source_sshkey |>>
86 exec { "postgres-make-backup-sshauthkeys":
87 command => "/usr/local/bin/postgres-make-backup-sshauthkeys",
92 # Maintain /etc/nagios/dsa-check-backuppg.conf
94 file { '/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d':
95 ensure => 'directory',
99 source => 'puppet:///files/empty/',
100 notify => Exec['update dsa-check-backuppg-manual.conf'],
102 file { '/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/manual.conf':
103 content => template('postgres/backup_server/dsa-check-backuppg-manual.conf.erb'),
104 notify => Exec['update dsa-check-backuppg-manual.conf']
106 file { '/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/moszumanska.conf':
107 ensure => ($::hostname in [backuphost]) ? {
117 notify => Exec['update dsa-check-backuppg-manual.conf']
119 File<<| tag == $postgres::backup_server::globals::tag_dsa_check_backupp |>>
120 ensure_packages ( "libhash-merge-simple-perl", { ensure => 'installed' })
121 exec { "update dsa-check-backuppg-manual.conf":
123 perl -MYAML=LoadFile,Dump -MHash::Merge::Simple=merge -E 'say Dump(merge(map{LoadFile($_)}@ARGV))' /etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/*.conf > /etc/nagios/dsa-check-backuppg.conf
130 # Maintain .pgpass file on backup servers
132 concat { $postgres::backup_server::globals::pgpassfile:
133 owner => 'debbackup',
134 group => 'debbackup',
137 concat::fragment{ 'pgpass-local':
138 target => $postgres::backup_server::globals::pgpassfile,
139 source => '/home/debbackup/.pgpass-local',
142 Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_source_pgpassline |>>
145 define postgres::backup_server::register_backup_clienthost (
146 $sshpubkey = $::postgresql_key,
147 $ipaddrlist = join(getfromhash($site::nodeinfo, 'ldap', 'ipHostNumber'), ","),
148 $hostname = $::hostname,
150 include postgres::backup_server::globals
153 $addr = assert_type(String[1], $ipaddrlist)
154 @@concat::fragment { "postgresql::server::backup-source-clienthost::$name::$fqdn":
155 target => $postgres::backup_server::globals::sshkeys_sources ,
157 ${hostname} ${addr} ${sshpubkey}
159 tag => $postgres::backup_server::globals::tag_source_sshkey,
164 define postgres::backup_server::register_backup_cluster (
165 $hostname = $::hostname,
173 include postgres::backup_server::globals
175 # foobar.debian.org:5432:*:debian-backup:swordfish
176 @@concat::fragment { "postgresql::server::backup-source-pgpassline::$hostname::$pg_port::$pg_role":
177 target => $postgres::backup_server::globals::pgpassfile,
179 ${fqdn}:${pg_port}:*:${pg_role}:${pg_password}
181 tag => $postgres::backup_server::globals::tag_source_pgpassline,
184 # vittoria.debian.org 5432 debian-backup main 9.6
185 @@concat::fragment { "postgresql::server::backup-source-make-base-backup-entry::$hostname::$pg_port::$pg_role":
186 target => $postgres::backup_server::globals::make_base_backups,
188 ${fqdn} ${pg_port} ${pg_role} ${pg_cluster} ${pg_version}
190 tag => $postgres::backup_server::globals::tag_base_backup,
193 @@file { "/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/${hostname}-${pg_cluster}.conf":
200 tag => $postgres::backup_server::globals::tag_dsa_check_backupp,
201 notify => Exec['update dsa-check-backuppg-manual.conf']