mirror of
https://gitea.0xace.cc/ansible-galaxy/postgresql.git
synced 2024-11-29 02:06:39 +00:00
84 lines
2.4 KiB
YAML
84 lines
2.4 KiB
YAML
- 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
|
|
|
|
- name: Check if database folder is empty before proceeding
|
|
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
|
|
shell: "{{ postgresql_restore_dbs_from_backup_command }}"
|
|
become_user: postgres
|
|
|
|
- name: Include PostgreSQL configuration
|
|
vars:
|
|
postgresql_archive_command: "cd ."
|
|
postgresql_restore_command: "{{ postgresql_restore_wals_from_backup_command }}"
|
|
recovery_target_time: "{{ postgresql_wal_g_pitr }}"
|
|
include_tasks: config.yaml
|
|
|
|
- name: Create recovery.signal file
|
|
file:
|
|
name: "{{ postgresql_data_dir }}/recovery.signal"
|
|
state: touch
|
|
become_user: postgres
|
|
|
|
- name: Start PostgreSQL for recovery
|
|
systemd:
|
|
daemon_reload: true
|
|
name: "{{ postgresql_unit_name }}"
|
|
state: started
|
|
masked: no
|
|
register: postgresql_start_for_recovery
|
|
|
|
- name: Ping PostgreSQL server
|
|
community.postgresql.postgresql_ping:
|
|
db: "{{ postgresql_superuser_db }}"
|
|
register: postgresql_ping
|
|
until: postgresql_ping.is_available
|
|
retries: 100
|
|
delay: 20
|
|
|
|
- name: debug
|
|
debug:
|
|
msg: "{{ postgresql_ping }}"
|
|
|
|
- name: Reset {{ postgresql_superuser_username }} password after restore
|
|
become_user: "{{ postgresql_user }}"
|
|
community.postgresql.postgresql_query:
|
|
db: "{{ postgresql_superuser_db }}"
|
|
query: ALTER USER {{ postgresql_superuser_username }} with password '{{ postgresql_superuser_password }}';
|
|
|
|
- name: Stop PostgreSQL
|
|
systemd:
|
|
daemon_reload: true
|
|
name: "{{ postgresql_unit_name }}"
|
|
state: stopped
|
|
masked: no
|
|
register: postgresql_stop
|
|
|
|
- name: Include PostgreSQL configuration
|
|
include_tasks: config.yaml
|