postgresql/tasks/restore.yaml

93 lines
2.5 KiB
YAML
Raw Normal View History

2023-02-17 15:13:18 +00:00
- name: Restore database
when: postgresql_wal_g_force_delete_and_restore
block:
- name: Stop PostgreSQL
systemd:
daemon_reload: true
name: "{{ postgresql_unit_name }}"
state: stopped
masked: no
- name: Force purge database directory
file:
path: "{{ postgresql_data_dir }}"
state: absent
- name: Recreate database directory
file:
path: "{{ postgresql_data_dir }}"
state: directory
become_user: postgres
2023-07-31 20:44:44 +00:00
- name: Check if database folder is empty before proceeding
2023-02-17 15:13:18 +00:00
find:
paths: "{{ postgresql_data_dir }}"
register: postgresql_files_found
- name: Restore database
when:
- postgresql_files_found.matched == 0
block:
- name: Restore database dir from backup
2023-07-31 20:44:44 +00:00
shell: "{{ postgresql_restore_dbs_from_backup_command }}"
2023-02-17 15:13:18 +00:00
become_user: postgres
2023-07-21 14:14:47 +00:00
2023-02-17 15:13:18 +00:00
- name: Include PostgreSQL configuration
vars:
2023-03-15 09:26:09 +00:00
postgresql_archive_command: "cd ."
2023-07-31 20:44:44 +00:00
postgresql_restore_command: "{{ postgresql_restore_wals_from_backup_command }}"
2023-02-17 15:13:18 +00:00
include_tasks: config.yaml
2023-07-21 14:14:47 +00:00
2023-02-17 15:13:18 +00:00
- name: Create recovery.signal file
2023-07-21 14:14:47 +00:00
file:
2023-02-17 15:13:18 +00:00
name: "{{ postgresql_data_dir }}/recovery.signal"
state: touch
become_user: postgres
2023-07-21 14:14:47 +00:00
#- name: Create standby.signal file
# file:
# name: "{{ postgresql_data_dir }}/standby.signal"
# state: touch
# become_user: postgres
2023-02-17 15:13:18 +00:00
- name: Start PostgreSQL for recovery
systemd:
daemon_reload: true
name: "{{ postgresql_unit_name }}"
state: started
masked: no
register: postgresql_start_for_recovery
2023-07-21 14:14:47 +00:00
2023-02-17 15:13:18 +00:00
- name: Ping PostgreSQL server
vars:
ansible_python_interpreter: '/usr/bin/env python3'
community.postgresql.postgresql_ping:
db: "{{ postgresql_superuser_db }}"
login_user: "{{ postgresql_superuser_username }}"
2023-07-21 14:14:47 +00:00
login_password: "{{ postgresql_superuser_password }}"
2023-02-17 15:13:18 +00:00
register: postgresql_ping
until: postgresql_ping.is_available
retries: 60
delay: 20
2023-07-21 14:14:47 +00:00
2023-02-17 15:13:18 +00:00
- name: debug
debug:
msg: "{{ postgresql_ping }}"
- name: Stop PostgreSQL
systemd:
daemon_reload: true
name: "{{ postgresql_unit_name }}"
state: stopped
masked: no
register: postgresql_stop
- name: Create promote trigger file
2023-07-21 14:14:47 +00:00
file:
2023-02-17 15:13:18 +00:00
name: "{{ postgresql_promote_trigger_file }}"
state: touch
become_user: postgres
2023-07-21 14:14:47 +00:00
- name: Include PostgreSQL configuration
include_tasks: config.yaml