+#!/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