]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Pause replication before the postgresql backup
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 28 May 2019 08:32:51 +0000 (10:32 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 28 May 2019 08:46:41 +0000 (10:46 +0200)
modules/profile/manifests/postgresql/backup_dump.pp
modules/profile/templates/postgresql/backup_psql.sh.erb [new file with mode: 0644]

index 7578027513f0be18d5c452a8eb0aaf4afae44ca4..cae20f748180833d4fe4065ebcfe43472516a9a4 100644 (file)
@@ -30,13 +30,18 @@ define profile::postgresql::backup_dump (
     $pg_port_arg = ""
   }
 
+  file { "/usr/local/sbin/backup_psql_$pg_host.sh":
+    mode    => "0755",
+    content => template("profile/postgresql/backup_psql.sh.erb"),
+  }
+
   if ($pg_host == "eldiron.immae.eu") {
     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$pg_port_arg -f $pg_backup_path/\$(date -Iseconds).sql",
+          command     => "/usr/local/sbin/backup_psql_$pg_host.sh",
           user        => $pg_user,
           hour        => "22,4,10,16",
           minute      => 0,
@@ -57,7 +62,7 @@ define profile::postgresql::backup_dump (
       require => [File[$pg_backup_path], File[$pg_path]],
       jobs    => [
         {
-          command     => "/usr/bin/pg_dumpall -h $pg_path$pg_port_arg -f $pg_backup_path/\$(date -Iseconds).sql",
+          command     => "/usr/local/sbin/backup_psql_$pg_host.sh",
           user        => $pg_user,
           hour        => "22,4,10,16",
           minute      => 0,
diff --git a/modules/profile/templates/postgresql/backup_psql.sh.erb b/modules/profile/templates/postgresql/backup_psql.sh.erb
new file mode 100644 (file)
index 0000000..cf353b0
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+set -euo pipefail
+
+resume_replication() {
+  /usr/bin/psql -h <%= @pg_path %><%= @pg_port_arg %> -c "SELECT pg_wal_replay_resume();" >/dev/null || echo "impossible to resume replication"
+}
+
+trap resume_replication EXIT
+
+/usr/bin/psql -h <%= @pg_path %><%= @pg_port_arg %> -c "SELECT pg_wal_replay_pause();" >/dev/null || (echo "impossible to pause replication" && false)
+
+/usr/bin/pg_dumpall -h <%= @pg_path %><%= @pg_port_arg %> -f <%= @pg_backup_path %>/$(date -Iseconds).sql