rewrite restore logic

This commit is contained in:
ace 2023-07-21 17:14:47 +03:00
parent a20385be58
commit e201c69b36
Signed by: ace
GPG Key ID: 2C08973DD37A76FD
7 changed files with 51 additions and 26 deletions

View File

@ -13,20 +13,23 @@ postgresql_ssl_keep_nonssl_endpoint: false
postgresql_self_signed_cert: true postgresql_self_signed_cert: true
postgresql_self_signed_cert_name: "cert" postgresql_self_signed_cert_name: "cert"
## Backup and restore options ## WAL-G backup and restore options
postgresql_wal_g_install: false postgresql_wal_g_install: false
postgresql_wal_g_restore: false postgresql_wal_g_restore_from_backup: false
postgresql_wal_g_force_delete_and_restore: false postgresql_wal_g_force_delete_and_restore: false
postgresql_wal_g_config_name: ".walg.json" postgresql_wal_g_config_name: ".walg.json"
postgresql_wal_g_restore_config_name: ".walg-restore.json" postgresql_wal_g_restore_config_name: ".walg-restore.json"
postgresql_wal_g_pitr: 'latest'
postgresql_wal_g_restore_backup_name: 'LATEST'
postgresql_wal_g_binary_name: "wal-g-pg" postgresql_wal_g_binary_name: "wal-g-pg"
postgresql_wal_g_postgresql_pitr: "LATEST"
postgresql_recovery_target_time: "" postgresql_recovery_target_time: ""
postgresql_promote_trigger_file: "{{ postgresql_data_dir }}/promote.trigger" postgresql_promote_trigger_file: "{{ postgresql_data_dir }}/promote.trigger"
postgresql_password_encryption_algorithm: "scram-sha-256" postgresql_password_encryption_algorithm: "scram-sha-256"
postgresql_default_parameters: postgresql_default_parameters:
data_directory: '{{ postgresql_data_dir }}' data_directory: '{{ postgresql_data_dir }}'
archive_mode: "{{ postgresql_archive_mode | default('on') }}"
listen_addresses: '*' listen_addresses: '*'
max_connections: '1000' max_connections: '1000'
superuser_reserved_connections: '5' superuser_reserved_connections: '5'
@ -59,8 +62,9 @@ postgresql_default_parameters:
postgresql_backup_parameters: postgresql_backup_parameters:
archive_command: "{{ postgresql_archive_command | default('cd .')}}" archive_command: "{{ postgresql_archive_command | default('cd .')}}"
postgresql_restore_parameters:
restore_command: "{{ postgresql_restore_command | default('cd .') }}" restore_command: "{{ postgresql_restore_command | default('cd .') }}"
archive_mode: "{{ postgresql_archive_mode | default('on') }}"
postgresql_log_dir: "/var/log/postgresql" postgresql_log_dir: "/var/log/postgresql"

View File

@ -19,8 +19,11 @@
- name: Merge backup options for PostgreSQL config - name: Merge backup options for PostgreSQL config
set_fact: set_fact:
postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_backup_parameters|default({}), recursive=true) }}" postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_backup_parameters, recursive=true) }}"
when:
- name: Merge restore options for PostgreSQL config
set_fact:
postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_restore_parameters, recursive=true) }}"
- name: Propagate PostgreSQL configs - name: Propagate PostgreSQL configs
block: block:

View File

@ -6,6 +6,10 @@
include_tasks: config.yaml include_tasks: config.yaml
tags: postgresql_configuration tags: postgresql_configuration
- name: "Manage TLS/SSL certificates"
include_tasks: cacert.yaml
when: postgresql_ssl
- name: Include WAL-G role - name: Include WAL-G role
ansible.builtin.include_role: ansible.builtin.include_role:
name: wal-g name: wal-g
@ -16,6 +20,10 @@
wal_g_restore: "{{ postgresql_wal_g_restore }}" wal_g_restore: "{{ postgresql_wal_g_restore }}"
when: postgresql_wal_g_install when: postgresql_wal_g_install
- name: Include PostgreSQL restore
include_tasks: restore.yaml
when: postgresql_wal_g_restore_from_backup
- name: "PostgreSQL initdb" - name: "PostgreSQL initdb"
become_user: "{{ postgresql_superuser_username }}" become_user: "{{ postgresql_superuser_username }}"
shell: "/usr/lib/postgresql/{{ postgresql_major_version }}/bin/initdb -D {{ postgresql_data_dir }} --username {{ postgresql_superuser_username }} --auth-local peer --auth-host {{ postgresql_password_encryption_algorithm }} --no-instructions" shell: "/usr/lib/postgresql/{{ postgresql_major_version }}/bin/initdb -D {{ postgresql_data_dir }} --username {{ postgresql_superuser_username }} --auth-local peer --auth-host {{ postgresql_password_encryption_algorithm }} --no-instructions"

View File

@ -6,7 +6,10 @@
- name: Merge backup options for PostgreSQL config - name: Merge backup options for PostgreSQL config
set_fact: set_fact:
postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_backup_parameters|default({}), recursive=true) }}" postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_backup_parameters|default({}), recursive=true) }}"
when:
- name: Merge restore options for PostgreSQL config
set_fact:
postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_restore_parameters|default({}), recursive=true) }}"
- name: Propagate PostgreSQL configs - name: Propagate PostgreSQL configs
block: block:

View File

@ -27,6 +27,10 @@
- name: Include data direcory - name: Include data direcory
include_tasks: data_dir.yaml include_tasks: data_dir.yaml
- name: "Manage TLS/SSL certificates"
include_tasks: cacert.yaml
when: postgresql_ssl
- name: Include WAL-G role - name: Include WAL-G role
ansible.builtin.include_role: ansible.builtin.include_role:
name: wal-g name: wal-g
@ -39,7 +43,7 @@
- name: Include PostgreSQL restore - name: Include PostgreSQL restore
include_tasks: restore.yaml include_tasks: restore.yaml
when: postgresql_wal_g_restore when: postgresql_wal_g_restore_from_backup
- name: PostgreSQL Initdb - name: PostgreSQL Initdb
shell: "/usr/pgsql-{{ postgresql_major_version }}/bin/postgresql-{{ postgresql_major_version }}-setup initdb --username {{ postgresql_superuser_username }} --auth-host {{ postgresql_password_encryption_algorithm }}" shell: "/usr/pgsql-{{ postgresql_major_version }}/bin/postgresql-{{ postgresql_major_version }}-setup initdb --username {{ postgresql_superuser_username }} --auth-host {{ postgresql_password_encryption_algorithm }}"

View File

@ -27,9 +27,9 @@
include_tasks: "{{ ansible_facts['os_family'] }}/main.yaml" include_tasks: "{{ ansible_facts['os_family'] }}/main.yaml"
tags: postgresql_setup tags: postgresql_setup
- name: "Manage TLS/SSL certificates" #- name: "Manage TLS/SSL certificates"
include_tasks: cacert.yaml # include_tasks: cacert.yaml
when: postgresql_ssl # when: postgresql_ssl
- name: Enable and start PostgreSQL - name: Enable and start PostgreSQL
systemd: systemd:

View File

@ -29,7 +29,7 @@
- postgresql_files_found.matched == 0 - postgresql_files_found.matched == 0
block: block:
- name: Restore database dir from backup - name: Restore database dir from backup
shell: "{{ postgresql_wal_g_binary_name ~ ' --config ' ~ postgresql_home_dir ~ '/' ~ postgresql_wal_g_restore_config_name ~ ' backup-fetch ' ~ postgresql_data_dir ~ ' ' ~ postgresql_wal_g_postgresql_pitr }}" shell: "{{ postgresql_wal_g_binary_name ~ ' --config ' ~ postgresql_home_dir ~ '/' ~ postgresql_wal_g_restore_config_name ~ ' backup-fetch ' ~ postgresql_data_dir ~ ' ' ~ postgresql_wal_g_restore_backup_name }}"
become_user: postgres become_user: postgres
- name: Include PostgreSQL configuration - name: Include PostgreSQL configuration
@ -44,11 +44,11 @@
state: touch state: touch
become_user: postgres become_user: postgres
- name: Create standby.signal file #- name: Create standby.signal file
file: # file:
name: "{{ postgresql_data_dir }}/standby.signal" # name: "{{ postgresql_data_dir }}/standby.signal"
state: touch # state: touch
become_user: postgres # become_user: postgres
- name: Start PostgreSQL for recovery - name: Start PostgreSQL for recovery
systemd: systemd:
@ -87,3 +87,6 @@
name: "{{ postgresql_promote_trigger_file }}" name: "{{ postgresql_promote_trigger_file }}"
state: touch state: touch
become_user: postgres become_user: postgres
- name: Include PostgreSQL configuration
include_tasks: config.yaml