]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - modules/profile/manifests/postgresql/backup_dump.pp
Fix crontab command % escape
[perso/Immae/Projets/Puppet.git] / modules / profile / manifests / postgresql / backup_dump.pp
index 10e349a560d0b9126a75192eca2d2daa1af05e7c..fcc2085883ce05f5a043721c966f6386f7c155fd 100644 (file)
@@ -1,6 +1,7 @@
 define profile::postgresql::backup_dump (
-  String $pg_user  = "postgres",
-  String $pg_group = "postgres",
+  String                             $pg_user  = "postgres",
+  String                             $pg_group = "postgres",
+  Optional[Variant[String, Integer]] $pg_port  = undef,
 ) {
   $base_path        = $title
   $pg_path          = "$base_path/postgresql"
@@ -23,12 +24,18 @@ define profile::postgresql::backup_dump (
     require => File[$base_path],
   }
 
+  if $pg_port and !empty($pg_port) {
+    $pg_port_arg = " -p $pg_port"
+  } else {
+    $pg_port_arg = ""
+  }
+
   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",
+        command     => "/usr/bin/pg_dumpall -h $pg_path$pg_port_arg -f $pg_backup_path/\$(date -Iseconds).sql",
         user        => $pg_user,
         hour        => "22,4,10,16",
         minute      => 0,
@@ -42,7 +49,7 @@ define profile::postgresql::backup_dump (
         description => "Cleanup the database backups",
       },
       {
-        command     => "cd $pg_backup_path ; /usr/bin/rm -f $(ls -1 *T22*.sql | log2rotate --skip 7 --fuzz 7 --delete --format='%Y-%m-%dT%H:%M:%S+02:00.sql')",
+        command     => "cd $pg_backup_path ; /usr/bin/rm -f $(ls -1 *T22*.sql | log2rotate --skip 7 --fuzz 7 --delete --format='\%Y-\%m-\%dT\%H:\%M:\%S+02:00.sql')",
         user        => $pg_user,
         hour        => 3,
         minute      => 1,
@@ -50,4 +57,13 @@ define profile::postgresql::backup_dump (
       },
     ]
   }
+
+  @profile::monitoring::local_service { "Last postgresql dump in $pg_backup_path is not too old":
+    sudos => {
+      "naemon-postgresql-dumps-$pg_host" => "naemon  ALL=($pg_user) NOPASSWD: /usr/bin/find $pg_backup_path -mindepth 1 -maxdepth 1 -printf %T@?n",
+    },
+    local => {
+      check_command => "check_last_file_date!$pg_backup_path!7!$pg_user",
+    }
+  }
 }