]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - modules/profile/templates/postgresql/backup_psql.sh.erb
Pause replication before the postgresql backup
[perso/Immae/Projets/Puppet.git] / modules / profile / templates / postgresql / backup_psql.sh.erb
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