aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-05-16 12:21:11 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-05-16 12:30:32 +0200
commite4a2c1723d7ac780ca5e3f23b0cdbf60033402e9 (patch)
tree4e559d3867ed818abd3090ee1f29da9ef896674d /modules
parent1c90c6913652e0ec7489ed22941e4e6a31d55912 (diff)
downloadPuppet-e4a2c1723d7ac780ca5e3f23b0cdbf60033402e9.tar.gz
Puppet-e4a2c1723d7ac780ca5e3f23b0cdbf60033402e9.tar.zst
Puppet-e4a2c1723d7ac780ca5e3f23b0cdbf60033402e9.zip
Add cron job to backup postgresql
Diffstat (limited to 'modules')
-rw-r--r--modules/role/manifests/backup/postgresql.pp30
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/role/manifests/backup/postgresql.pp b/modules/role/manifests/backup/postgresql.pp
index 51ce37e..e635611 100644
--- a/modules/role/manifests/backup/postgresql.pp
+++ b/modules/role/manifests/backup/postgresql.pp
@@ -96,6 +96,7 @@ class role::backup::postgresql inherits role::backup {
96 96
97 $pg_backup_hosts.each |$pg_backup_host, $pg_infos| { 97 $pg_backup_hosts.each |$pg_backup_host, $pg_infos| {
98 $pg_path = "$mountpoint/$pg_backup_host/postgresql" 98 $pg_path = "$mountpoint/$pg_backup_host/postgresql"
99 $pg_backup_path = "$mountpoint/$pg_backup_host/postgresql_backup"
99 $pg_host = "$pg_backup_host" 100 $pg_host = "$pg_backup_host"
100 $pg_port = $pg_infos["dbport"] 101 $pg_port = $pg_infos["dbport"]
101 102
@@ -132,6 +133,35 @@ class role::backup::postgresql inherits role::backup {
132 require => File["$mountpoint/$pg_backup_host"], 133 require => File["$mountpoint/$pg_backup_host"],
133 } 134 }
134 135
136 file { $pg_backup_path:
137 ensure => directory,
138 owner => $pg_user,
139 group => $pg_group,
140 mode => "0700",
141 require => File["$mountpoint/$pg_backup_host"],
142 }
143
144 cron::job::multiple { "backup_psql_$pg_host":
145 ensure => "present",
146 require => [File[$pg_backup_path], File[$pg_path]],
147 jobs => [
148 {
149 command => "/usr/bin/pg_dumpall -h $pg_path -f $pg_backup_path/\$(date -Iseconds).sql",
150 user => $pg_user,
151 hour => "22,4,10,16",
152 minute => 0,
153 description => "Backup the database",
154 },
155 {
156 command => "/usr/bin/rm -f $(ls -1 $pg_backup_path/*.sql | sort -r | sed -e '1,16d')",
157 user => $pg_user,
158 hour => 3,
159 minute => 0,
160 description => "Cleanup the database backups",
161 },
162 ]
163 }
164
135 exec { "pg_basebackup $pg_path": 165 exec { "pg_basebackup $pg_path":
136 cwd => $pg_path, 166 cwd => $pg_path,
137 user => $pg_user, 167 user => $pg_user,