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': ensure => absent; }
40 file { '/var/lib/dsa/postgres-make-base-backups':
45 concat::fragment { 'dsa-puppet-stuff--postgres-make_base_backups':
46 target => '/etc/cron.d/dsa-puppet-stuff',
48 */30 * * * * debbackup sleep \$(( RANDOM \\% 1500 )) chronic ${$postgres::backup_server::globals::make_base_backups}
53 # Maintain authorized_keys file on backup servers for WAL shipping
55 # do not let other hosts directly build our authorized_keys file,
56 # instead go via a script that somewhat validates intput
57 file { '/etc/dsa/postgresql-backup':
58 ensure => 'directory',
60 file { '/usr/local/bin/postgres-make-backup-sshauthkeys':
61 content => template('postgres/backup_server/postgres-make-backup-sshauthkeys.erb'),
63 notify => Exec['postgres-make-backup-sshauthkeys'],
65 file { '/usr/local/bin/postgres-make-one-base-backup':
66 source => 'puppet:///modules/postgres/backup_server/postgres-make-one-base-backup',
69 file { '/etc/dsa/postgresql-backup/sshkeys-manual':
70 content => template('postgres/backup_server/sshkeys-manual.erb'),
71 notify => Exec['postgres-make-backup-sshauthkeys'],
73 concat { $postgres::backup_server::globals::sshkeys_sources:
74 notify => Exec['postgres-make-backup-sshauthkeys'],
76 concat::fragment { 'postgresql-backup/source-sshkeys-header':
77 target => $postgres::backup_server::globals::sshkeys_sources ,
79 # <name> <ip addresses> <key>
83 Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_source_sshkey |>>
84 exec { "postgres-make-backup-sshauthkeys":
85 command => "/usr/local/bin/postgres-make-backup-sshauthkeys",
90 # Maintain /etc/nagios/dsa-check-backuppg.conf
92 file { '/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d':
93 ensure => 'directory',
97 source => 'puppet:///files/empty/',
98 notify => Exec['update dsa-check-backuppg-manual.conf'],
100 file { '/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/manual.conf':
101 content => template('postgres/backup_server/dsa-check-backuppg-manual.conf.erb'),
102 notify => Exec['update dsa-check-backuppg-manual.conf']
104 file { '/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/moszumanska.conf':
105 ensure => ($::hostname in [backuphost]) ? {
115 notify => Exec['update dsa-check-backuppg-manual.conf']
117 File<<| tag == $postgres::backup_server::globals::tag_dsa_check_backupp |>>
118 ensure_packages ( "libhash-merge-simple-perl", { ensure => 'installed' })
119 exec { "update dsa-check-backuppg-manual.conf":
121 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
128 # Maintain .pgpass file on backup servers
130 concat { $postgres::backup_server::globals::pgpassfile:
131 owner => 'debbackup',
132 group => 'debbackup',
135 concat::fragment{ 'pgpass-local':
136 target => $postgres::backup_server::globals::pgpassfile,
137 source => '/home/debbackup/.pgpass-local',
140 Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_source_pgpassline |>>
143 define postgres::backup_server::register_backup_clienthost (
144 $sshpubkey = $::postgresql_key,
145 $ipaddrlist = join(getfromhash($site::nodeinfo, 'ldap', 'ipHostNumber'), ","),
146 $hostname = $::hostname,
148 include postgres::backup_server::globals
151 $addr = assert_type(String[1], $ipaddrlist)
152 @@concat::fragment { "postgresql::server::backup-source-clienthost::$name::$fqdn":
153 target => $postgres::backup_server::globals::sshkeys_sources ,
155 ${hostname} ${addr} ${sshpubkey}
157 tag => $postgres::backup_server::globals::tag_source_sshkey,
162 define postgres::backup_server::register_backup_cluster (
163 $hostname = $::hostname,
171 include postgres::backup_server::globals
173 # foobar.debian.org:5432:*:debian-backup:swordfish
174 @@concat::fragment { "postgresql::server::backup-source-pgpassline::$hostname::$pg_port::$pg_role":
175 target => $postgres::backup_server::globals::pgpassfile,
177 ${fqdn}:${pg_port}:*:${pg_role}:${pg_password}
179 tag => $postgres::backup_server::globals::tag_source_pgpassline,
182 # vittoria.debian.org 5432 debian-backup main 9.6
183 @@concat::fragment { "postgresql::server::backup-source-make-base-backup-entry::$hostname::$pg_port::$pg_role":
184 target => $postgres::backup_server::globals::make_base_backups,
186 ${fqdn} ${pg_port} ${pg_role} ${pg_cluster} ${pg_version}
188 tag => $postgres::backup_server::globals::tag_base_backup,
191 @@file { "/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/${hostname}-${pg_cluster}.conf":
198 tag => $postgres::backup_server::globals::tag_dsa_check_backupp,
199 notify => Exec['update dsa-check-backuppg-manual.conf']