From b722248ed7c4a7aba2b047855b983d72a9725209 Mon Sep 17 00:00:00 2001 From: Paul B Date: Thu, 28 May 2020 18:41:49 +0200 Subject: standby-clone: Allow cloning of standby server with pg_basebackup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right now the role assumes you have a base backup available with Barman. However if you don't have an initial barman backup you might want to clone the primary server directly to setup your standby server. This PR adds a new `primary.pg_basebackup` option to the cluster configuration which if enabled (set to `true`) will create a `/root/standby-clone-{{ postgres_version }}-{{ postgres_cluster_name }}.sh` script on the standby server which helps to initialise a standby server. ⚠️ Breaking change: the current role behavior which creates a cloning script fetching the initial backup from barman will not be enabled by default anymore. You will need to add the new `primary.restore_barman_directory` option in your role configuration to do so. ⚠️ --- tasks/postgres-cluster.yml | 6 +++++- tasks/postgres-standby-barman.yml | 4 ++-- tasks/postgres-standby-basebackup.yml | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tasks/postgres-standby-basebackup.yml (limited to 'tasks') diff --git a/tasks/postgres-cluster.yml b/tasks/postgres-cluster.yml index a8e96c1..4f62d31 100644 --- a/tasks/postgres-cluster.yml +++ b/tasks/postgres-cluster.yml @@ -60,7 +60,11 @@ - name: Add standby clone from barman script include: postgres-standby-barman.yml - when: postgres_barman_server is defined + when: postgres_barman_server is defined and postgres_primary.restore_barman_directory is defined + +- name: Add standby clone from pg_basebackup + include: postgres-standby-basebackup.yml + when: postgres_primary and postgres_primary.pg_basebackup is defined - name: Determine SSD or rotational disks raw: 'lsblk --noheadings --nodeps --raw --output=rota | grep -q 1' diff --git a/tasks/postgres-standby-barman.yml b/tasks/postgres-standby-barman.yml index 6a94b75..fb71d32 100644 --- a/tasks/postgres-standby-barman.yml +++ b/tasks/postgres-standby-barman.yml @@ -11,8 +11,8 @@ path: "{{ postgres_barman_path_prefix | default('~') }}" rsync_password_file: "{{ postgres_barman_rsync_enabled | ternary(' --password-file=/var/lib/postgresql/.rsync_pass ', '') }}" -- name: Copy secondary script - template: src=standby-clone.sh.j2 dest=/root/standby-clone-{{ postgres_version }}-{{ postgres_cluster_name }}.sh mode=0755 +- name: Copy secondary barman clone script + template: src=standby-barman-clone.sh.j2 dest=/root/standby-clone-{{ postgres_version }}-{{ postgres_cluster_name }}.sh mode=0755 - name: Copy rsync password file copy: diff --git a/tasks/postgres-standby-basebackup.yml b/tasks/postgres-standby-basebackup.yml new file mode 100644 index 0000000..db52d55 --- /dev/null +++ b/tasks/postgres-standby-basebackup.yml @@ -0,0 +1,4 @@ +--- +- name: Copy secondary pg_basebackup clone script + template: src=standby-pg_basebackup-clone.sh.j2 dest=/root/standby-clone-{{ postgres_version }}-{{ postgres_cluster_name }}.sh mode=0755 + no_log: true -- cgit v1.2.3