Puppet Class: pgprobackup::catalog
- Inherits:
- pgprobackup
- Defined in:
- manifests/catalog.pp
Summary
Manages host where backups are being storedOverview
Configures server for storing backups.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'manifests/catalog.pp', line 37
class pgprobackup::catalog (
Stdlib::AbsolutePath $backup_dir = $pgprobackup::backup_dir,
Optional[Stdlib::AbsolutePath] $log_dir = $pgprobackup::log_dir,
String $logrotate_template = 'pgprobackup/logrotate.conf.erb',
String $exported_ipaddress = "${facts['networking']['ip']}/32",
String $user = $pgprobackup::backup_user,
String $group = $pgprobackup::backup_user,
String $dir_mode = '0750',
Enum['present', 'absent'] $user_ensure = 'present',
String $user_shell = '/bin/bash',
Boolean $manage_ssh_keys = $pgprobackup::manage_ssh_keys,
Boolean $manage_host_keys = $pgprobackup::manage_host_keys,
Boolean $manage_pgpass = $pgprobackup::manage_pgpass,
Boolean $manage_hba = $pgprobackup::manage_hba,
Boolean $manage_cron = $pgprobackup::manage_cron,
Boolean $purge_cron = true,
Optional[Integer] $uid = undef,
String $host_group = $pgprobackup::host_group,
Integer $hba_entry_order = 50,
String $ssh_key_fact = $facts['pgprobackup_catalog_key'],
String $package_name = $pgprobackup::package_name,
Array[String] $versions = ['12'],
String $package_ensure = $pgprobackup::package_ensure,
) inherits pgprobackup {
class { 'pgprobackup::install':
versions => $versions,
package_name => $package_name,
package_ensure => $package_ensure,
}
group { $group:
ensure => $user_ensure,
}
user { $user:
ensure => $user_ensure,
uid => $uid,
gid => $group, # a primary group
home => $backup_dir,
shell => $user_shell,
require => Group[$group],
}
file { $backup_dir:
ensure => directory,
owner => $user,
group => $group,
mode => $dir_mode,
require => User[$user],
}
file { "${backup_dir}/backups":
ensure => directory,
owner => $user,
group => $group,
mode => $dir_mode,
require => File[$backup_dir],
}
file { "${backup_dir}/wal":
ensure => directory,
owner => $user,
group => $group,
mode => $dir_mode,
require => File[$backup_dir],
}
if $log_dir {
file { $log_dir:
ensure => directory,
owner => $user,
group => $group,
}
}
if $manage_ssh_keys {
file { "${backup_dir}/.ssh":
ensure => directory,
owner => $user,
group => $group,
mode => '0700',
require => File[$backup_dir],
}
file { "${backup_dir}/.ssh/known_hosts":
ensure => file,
owner => $user,
group => $group,
mode => '0600',
require => File["${backup_dir}/.ssh"],
}
# Add public ssh keys from DB instances as authorized keys
Ssh_authorized_key <<| tag == "pgprobackup-${host_group}-instance" |>>
}
if $manage_pgpass {
# create an empty .pgpass file
file { "${backup_dir}/.pgpass":
ensure => 'file',
owner => $user,
group => $group,
mode => '0600',
require => File[$backup_dir],
}
# Fill the .pgpass file
File_line <<| tag == "pgprobackup-${host_group}" |>>
}
Exec <<| tag == "pgprobackup_add_instance-${host_group}" |>>
if $manage_host_keys {
# Import db instances host keys
Sshkey <<| tag == "pgprobackup-${host_group}" |>>
# Export catalog's host key
@@sshkey { "pgprobackup-catalog-${facts['networking']['fqdn']}":
ensure => present,
host_aliases => [$facts['networking']['hostname'], $facts['networking']['fqdn'], $facts['networking']['ip']],
key => $facts['ssh']['ecdsa']['key'],
type => $pgprobackup::host_key_type,
target => '/var/lib/postgresql/.ssh/known_hosts',
tag => "pgprobackup-catalog-${host_group}",
}
}
if $manage_hba {
# sufficient for full backup with enabled WAL archiving
@@postgresql::server::pg_hba_rule { "pgprobackup ${facts['networking']['hostname']} access":
description => "pgprobackup ${facts['networking']['hostname']} access",
type => 'host',
database => $pgprobackup::db_name,
user => $pgprobackup::db_user,
address => $exported_ipaddress,
auth_method => 'md5',
order => $hba_entry_order,
tag => "pgprobackup-${host_group}",
}
# needed for streaming backups or full backup with --stream option
@@postgresql::server::pg_hba_rule { "pgprobackup ${facts['networking']['hostname']} replication":
description => "pgprobackup ${facts['networking']['hostname']} replication",
type => 'host',
database => 'replication',
user => $pgprobackup::db_user,
address => $exported_ipaddress,
auth_method => 'md5',
order => $hba_entry_order,
tag => "pgprobackup-${host_group}",
}
}
# Export (and add as authorized key) ssh key from pgbackup user
# to all DB instances in host_group. Key is generated/fetch via
# custom Facter function `pgprobackup_keygen`
if ($ssh_key_fact != undef and $ssh_key_fact != '') {
$ssh_key_splitted = split($ssh_key_fact, ' ')
@@ssh_authorized_key { "pgprobackup-${facts['networking']['fqdn']}":
ensure => present,
user => 'postgres',
type => $ssh_key_splitted[0],
key => $ssh_key_splitted[1],
tag => "pgprobackup-catalog-${host_group}",
}
}
if $manage_cron {
# Collect backup jobs to run
Cron <<| tag == "pgprobackup-${host_group}" |>>
# When enabled e.g. old entries will be removed
resources { 'cron':
purge => $purge_cron,
}
}
}
|