RT#7513 Get rid of most traces of moszumanska
[mirror/dsa-puppet.git] / modules / postgres / manifests / backup_server.pp
1 #
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'
6
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"
11 }
12
13 class postgres::backup_server {
14         include postgres::backup_server::globals
15
16         ####
17         # Regularly pull base backups
18         #
19         ensure_packages ( "postgresql-client-9.6", { ensure => 'installed' })
20
21         concat { $postgres::backup_server::globals::make_base_backups:
22                 mode => '0555',
23         }
24         concat::fragment { 'make-base-backups-header':
25                 target => $postgres::backup_server::globals::make_base_backups,
26                 content => template('postgres/backup_server/postgres-make-base-backups.erb'),
27                 order  => '00',
28         }
29         Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_base_backup |>>
30         concat::fragment { 'make-base-backups-tail':
31                 target => $postgres::backup_server::globals::make_base_backups,
32                 content  => @(EOTEMPLATE),
33                                 # EOF by make-base-backups-tail fragment
34                                 EOF
35                                 | EOTEMPLATE
36                 order  => '99',
37         }
38         file { '/etc/cron.d/puppet-postgres-make-base-backups': ensure => absent; }
39         file { '/var/lib/dsa/postgres-make-base-backups':
40                 ensure => directory,
41                 owner => 'debbackup',
42                 mode => '0755',
43         }
44         concat::fragment { 'dsa-puppet-stuff--postgres-make_base_backups':
45                 target => '/etc/cron.d/dsa-puppet-stuff',
46                 content  => @("EOF")
47                         */30 * * * * debbackup sleep $(( RANDOM \% 1200 )); chronic ${$postgres::backup_server::globals::make_base_backups}
48                         | EOF
49         }
50
51         ####
52         # Maintain authorized_keys file on backup servers for WAL shipping
53         #
54         # do not let other hosts directly build our authorized_keys file,
55         # instead go via a script that somewhat validates intput
56         file { '/etc/dsa/postgresql-backup':
57                 ensure => 'directory',
58         }
59         file { '/usr/local/bin/postgres-make-backup-sshauthkeys':
60                 content => template('postgres/backup_server/postgres-make-backup-sshauthkeys.erb'),
61                 mode   => '0555',
62                 notify  => Exec['postgres-make-backup-sshauthkeys'],
63         }
64         file { '/usr/local/bin/postgres-make-one-base-backup':
65                 source  => 'puppet:///modules/postgres/backup_server/postgres-make-one-base-backup',
66                 mode   => '0555'
67         }
68         file { '/etc/dsa/postgresql-backup/sshkeys-manual':
69                 content => template('postgres/backup_server/sshkeys-manual.erb'),
70                 notify  => Exec['postgres-make-backup-sshauthkeys'],
71         }
72         concat { $postgres::backup_server::globals::sshkeys_sources:
73                 notify  => Exec['postgres-make-backup-sshauthkeys'],
74         }
75         concat::fragment { 'postgresql-backup/source-sshkeys-header':
76                 target => $postgres::backup_server::globals::sshkeys_sources ,
77                 content  => @(EOF),
78                                 # <name> <ip addresses> <key>
79                                 | EOF
80                 order  => '00',
81         }
82         Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_source_sshkey |>>
83         exec { "postgres-make-backup-sshauthkeys":
84                 command => "/usr/local/bin/postgres-make-backup-sshauthkeys",
85                 refreshonly => true,
86         }
87
88         ####
89         # Maintain /etc/nagios/dsa-check-backuppg.conf
90         #
91         file { '/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d':
92                 ensure => 'directory',
93                 purge   => true,
94                 force   => true,
95                 recurse => true,
96                 source  => 'puppet:///files/empty/',
97                 notify => Exec['update dsa-check-backuppg-manual.conf'],
98         }
99         file { '/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/manual.conf':
100                 content => template('postgres/backup_server/dsa-check-backuppg-manual.conf.erb'),
101                 notify => Exec['update dsa-check-backuppg-manual.conf']
102         }
103         File<<| tag == $postgres::backup_server::globals::tag_dsa_check_backupp |>>
104         ensure_packages ( "libhash-merge-simple-perl", { ensure => 'installed' })
105         exec { "update dsa-check-backuppg-manual.conf":
106                 command  => @(EOF),
107                                 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
108                                 | EOF
109                 provider => shell,
110                 refreshonly => true,
111         }
112
113         ####
114         # Maintain .pgpass file on backup servers
115         # #
116         concat { $postgres::backup_server::globals::pgpassfile:
117                 owner => 'debbackup',
118                 group => 'debbackup',
119                 mode  => '0400'
120         }
121         concat::fragment{ 'pgpass-local':
122                 target => $postgres::backup_server::globals::pgpassfile,
123                 source => '/home/debbackup/.pgpass-local',
124                 order  => '00'
125         }
126         Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_source_pgpassline |>>
127 }
128
129 define postgres::backup_server::register_backup_clienthost (
130         $sshpubkey = $::postgresql_key,
131         $ipaddrlist = join(getfromhash($site::nodeinfo, 'ldap', 'ipHostNumber'), ","),
132         $hostname = $::hostname,
133 ) {
134         include postgres::backup_server::globals
135
136         if $sshpubkey {
137                 $addr = assert_type(String[1], $ipaddrlist)
138                 @@concat::fragment { "postgresql::server::backup-source-clienthost::$name::$fqdn":
139                         target => $postgres::backup_server::globals::sshkeys_sources ,
140                         content  => @("EOF"),
141                                         ${hostname} ${addr} ${sshpubkey}
142                                         | EOF
143                         tag     => $postgres::backup_server::globals::tag_source_sshkey,
144                 }
145         }
146 }
147
148 define postgres::backup_server::register_backup_cluster (
149         $hostname = $::hostname,
150         $fqdn = $::fqdn,
151         $pg_port,
152         $pg_role,
153         $pg_password,
154         $pg_cluster,
155         $pg_version,
156 ) {
157         include postgres::backup_server::globals
158
159         # foobar.debian.org:5432:*:debian-backup:swordfish
160         @@concat::fragment { "postgresql::server::backup-source-pgpassline::$hostname::$pg_port::$pg_role":
161                 target => $postgres::backup_server::globals::pgpassfile,
162                 content => @("EOF"),
163                                 ${fqdn}:${pg_port}:*:${pg_role}:${pg_password}
164                                 | EOF
165                 tag     => $postgres::backup_server::globals::tag_source_pgpassline,
166         }
167         #
168         # vittoria.debian.org   5432    debian-backup           main            9.6
169         @@concat::fragment { "postgresql::server::backup-source-make-base-backup-entry::$hostname::$pg_port::$pg_role":
170                 target => $postgres::backup_server::globals::make_base_backups,
171                 content => @("EOF"),
172                                 ${fqdn} ${pg_port}      ${pg_role}      ${pg_cluster}   ${pg_version}
173                                 | EOF
174                 tag     => $postgres::backup_server::globals::tag_base_backup,
175         }
176
177         @@file { "/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/${hostname}-${pg_cluster}.conf":
178                 content  => @("EOF"),
179                                 --- 
180                                 backups:
181                                   ${hostname}:
182                                     ${pg_cluster}:
183                                 | EOF
184                 tag     => $postgres::backup_server::globals::tag_dsa_check_backupp,
185                 notify  => Exec['update dsa-check-backuppg-manual.conf']
186         }
187 }