Move list of clusters to make a base backup of from the script to a conffile
[mirror/dsa-puppet.git] / modules / postgres / manifests / backup_server.pp
index e42cf8c..0da5594 100644 (file)
+#
 class postgres::backup_server {
-       package { 'postgresql-client-9.1':
-               ensure => installed
-       }
-       package { 'postgresql-client-9.4':
-               ensure => installed
-       }
+  include postgres::backup_server::globals
 
-       file { '/usr/local/bin/postgres-make-base-backups':
-               source => 'puppet:///modules/postgres/backup_server/postgres-make-base-backups',
-               mode   => '0555',
-       }
-       if $::hostname in [backuphost] {
-               file { '/etc/cron.d/puppet-postgres-make-base-backups':
-                       content  => "20 1 * * 0 debbackup chronic /usr/local/bin/postgres-make-base-backups\n",
-               }
-       } else  {
-               file { '/etc/cron.d/puppet-postgres-make-base-backups':
-                       content  => "20 0 * * 6 debbackup chronic /usr/local/bin/postgres-make-base-backups\n",
-               }
-       }
+  ensure_packages ( [
+    'libhash-merge-simple-perl',
+    'libyaml-perl',
+    'python-yaml',
+    'pigz',
+    'postgresql-client',
+    'postgresql-client-9.6',
+  ], {
+    ensure => 'installed'
+  })
+
+  ####
+  # Regularly pull base backups
+  #
+  concat { $postgres::backup_server::globals::base_backup_clusters:
+    ensure_newline => true,
+  }
+  Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_base_backup |>>
+
+  file { '/usr/local/bin/postgres-make-base-backups':
+    mode    => '0555',
+    content => template('postgres/backup_server/postgres-make-base-backups.erb'),
+  }
+  file { '/var/lib/dsa/postgres-make-base-backups':
+    ensure => directory,
+    owner => 'debbackup',
+    mode => '0755',
+  }
+  concat::fragment { 'puppet-crontab--postgres-make_base_backups':
+    target => '/etc/cron.d/puppet-crontab',
+    content  => @("EOF")
+      */30 * * * * debbackup sleep $(( RANDOM \% 1200 )); chronic ${$postgres::backup_server::globals::make_base_backups}
+      | EOF
+  }
+
+  ####
+  # Maintain authorized_keys file on backup servers for WAL shipping
+  #
+  # do not let other hosts directly build our authorized_keys file,
+  # instead go via a script that somewhat validates intput
+  file { '/etc/dsa/postgresql-backup':
+    ensure => 'directory',
+  }
+  file { '/usr/local/bin/postgres-make-backup-sshauthkeys':
+    content => template('postgres/backup_server/postgres-make-backup-sshauthkeys.erb'),
+    mode   => '0555',
+    notify  => Exec['postgres-make-backup-sshauthkeys'],
+  }
+  file { '/usr/local/bin/postgres-make-one-base-backup':
+    source  => 'puppet:///modules/postgres/backup_server/postgres-make-one-base-backup',
+    mode   => '0555'
+  }
+  file { '/etc/dsa/postgresql-backup/sshkeys-manual':
+    content => template('postgres/backup_server/sshkeys-manual.erb'),
+    notify  => Exec['postgres-make-backup-sshauthkeys'],
+  }
+  concat { $postgres::backup_server::globals::sshkeys_sources:
+    notify  => Exec['postgres-make-backup-sshauthkeys'],
+  }
+  concat::fragment { 'postgresql-backup/source-sshkeys-header':
+    target => $postgres::backup_server::globals::sshkeys_sources ,
+    content  => @(EOF),
+        # <name> <ip addresses> <key>
+        | EOF
+    order  => '00',
+  }
+  Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_source_sshkey |>>
+  exec { "postgres-make-backup-sshauthkeys":
+    command => "/usr/local/bin/postgres-make-backup-sshauthkeys",
+    refreshonly => true,
+  }
+
+  ####
+  # Maintain /etc/nagios/dsa-check-backuppg.conf
+  #
+  file { '/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d':
+    ensure => 'directory',
+    purge   => true,
+    force   => true,
+    recurse => true,
+    source  => 'puppet:///files/empty/',
+    notify => Exec['update dsa-check-backuppg-manual.conf'],
+  }
+  file { '/etc/dsa/postgresql-backup/dsa-check-backuppg.conf.d/manual.conf':
+    content => template('postgres/backup_server/dsa-check-backuppg-manual.conf.erb'),
+    notify => Exec['update dsa-check-backuppg-manual.conf']
+  }
+  File<<| tag == $postgres::backup_server::globals::tag_dsa_check_backupp |>>
+  exec { "update dsa-check-backuppg-manual.conf":
+    command  => @(EOF),
+        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
+        | EOF
+    provider => shell,
+    refreshonly => true,
+  }
+
+  ####
+  # Maintain .pgpass file on backup servers
+  # #
+  concat { $postgres::backup_server::globals::pgpassfile:
+    owner => 'debbackup',
+    group => 'debbackup',
+    mode  => '0400'
+  }
+  concat::fragment{ 'pgpass-local':
+    target => $postgres::backup_server::globals::pgpassfile,
+    source => '/home/debbackup/.pgpass-local',
+    order  => '00'
+  }
+  Concat::Fragment <<| tag == $postgres::backup_server::globals::tag_source_pgpassline |>>
 }