$pg_backup_hosts.each |$pg_backup_host, $pg_infos| {
$pg_path = "$mountpoint/$pg_backup_host/postgresql"
+ $pg_backup_path = "$mountpoint/$pg_backup_host/postgresql_backup"
$pg_host = "$pg_backup_host"
$pg_port = $pg_infos["dbport"]
require => File["$mountpoint/$pg_backup_host"],
}
+ file { $pg_backup_path:
+ ensure => directory,
+ owner => $pg_user,
+ group => $pg_group,
+ mode => "0700",
+ require => File["$mountpoint/$pg_backup_host"],
+ }
+
+ cron::job::multiple { "backup_psql_$pg_host":
+ ensure => "present",
+ require => [File[$pg_backup_path], File[$pg_path]],
+ jobs => [
+ {
+ command => "/usr/bin/pg_dumpall -h $pg_path -f $pg_backup_path/\$(date -Iseconds).sql",
+ user => $pg_user,
+ hour => "22,4,10,16",
+ minute => 0,
+ description => "Backup the database",
+ },
+ {
+ command => "/usr/bin/rm -f $(ls -1 $pg_backup_path/*.sql | sort -r | sed -e '1,16d')",
+ user => $pg_user,
+ hour => 3,
+ minute => 0,
+ description => "Cleanup the database backups",
+ },
+ ]
+ }
+
exec { "pg_basebackup $pg_path":
cwd => $pg_path,
user => $pg_user,