3 # @param pg_version pg version of the cluster
4 # @param pg_cluster cluster name
5 # @param pg_port port of the postgres cluster
6 # @param db_backup_role replication role username
7 # @param db_backup_role_password password of the replication role
8 # @param do_role create the role (requires setup with postgresql::server)
9 # @param do_hba update pg_hba (requires setup with postgresql::server)
10 define postgres::backup_cluster(
12 String $pg_cluster = 'main',
13 Integer $pg_port = 5432,
14 String $db_backup_role = lookup('postgres::backup_cluster::db_backup_role'),
15 String $db_backup_role_password = hkdf('/etc/puppet/secret', "postgresql-${::hostname}-${$pg_cluster}-${pg_port}-backup_role}"),
16 Boolean $do_role = false,
17 Boolean $do_hba = false,
19 $datadir = "/var/lib/postgresql/${pg_version}/${pg_cluster}"
20 file { "${datadir}/.nobackup":
24 ## XXX - get these from the roles and ldap
26 $backup_servers_addrs = ['5.153.231.12/32', '93.94.130.161/32', '2001:41c8:1000:21::21:12/128', '2a02:158:380:280::161/128']
29 postgresql::server::role { $db_backup_role:
30 password_hash => postgresql_password($db_backup_role, $db_backup_role_password),
35 $backup_servers_addrs.each |String $address| {
36 postgresql::server::pg_hba_rule { "debian_backup-${address}":
37 description => 'Open up PostgreSQL for backups',
39 database => 'replication',
40 user => $db_backup_role,
46 ferm::rule::simple { "dsa-postgres-backup-${pg_port}":
47 description => 'Allow postgress access from backup host',
49 saddr => $backup_servers_addrs,
52 postgres::backup_server::register_backup_cluster { "backup-role-${::fqdn}}-${pg_port}":
54 pg_role => $db_backup_role,
55 pg_password => $db_backup_role_password,
56 pg_cluster => $pg_cluster,
57 pg_version => $pg_version,