#==============================================================#
# File      :   pitr.conf
# Desc      :   PgBackrest PITR Config for {{ pg_instance }} {{ pg_role }}
# Time      :   {{ '%Y-%m-%d %H:%M' | strftime }}
# Host      :   {{ pg_instance }} @ {{ inventory_hostname }}:{{ pg_port }}
# Path      :   /pg/conf/pitr.conf
# Note      :   ANSIBLE MANAGED, DO NOT CHANGE!
# License   :   Apache-2.0 @ https://pigsty.io/docs/about/license/
# Copyright :   2018-2026  Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#
# https://pgbackrest.org/command.html#command-restore
# https://pgbackrest.org/configuration.html#section-restore
# https://www.postgresql.org/docs/current/runtime-config-wal.html#RUNTIME-CONFIG-WAL-RECOVERY-TARGET
{% set p = pg_pitr                   | default({})           %}
{% set pitr_cluster    = p.cluster   | default(pg_cluster)   %}
{% set pitr_repo       = p.repo      | default(pgbackrest_repo[pgbackrest_method]) %}
{% set pitr_data       = p.data      | default(pg_data)      %}
{% set pitr_port       = p.port      | default(pg_port)      %}

# stanza
[{{ pitr_cluster }}]
pg1-path={{ pitr_data }}
pg1-port={{ pitr_port }}
{%if pg_mode|default('pgsql') == 'ivory' %}
archive-header-check=n
pg-version-force={{ pg_version|default(18) }}
{% endif %}

# config
[global]
{% for k,v in pitr_repo.items() %}
repo1-{{ k|replace('_', '-') }}={{ v|replace('${pg_cluster}', pitr_cluster ) }}
{% endfor %}

# logging
log-level-console=info
log-level-file=info
log-path={{ pgbackrest_log_dir }}

# restore
{% if p.archive|default(true)|bool %}
archive-mode=preserve
{% else %}
archive-mode=off
{% endif %}
link-all=n
delta=y

{% if p.db_exclude is defined and p.db_exclude | type_debug == 'list' and p.db_exclude|length > 0 %}
# exclude databases: {{ p.db_exclude|join(',') }}
{% for db in p.db_exclude %}
db-exclude={{ db }}
{% endfor %}
{% endif %}

{% if p.db_include is defined and p.db_include | type_debug == 'list' and p.db_include|length > 0 %}
# include databases: {{ p.db_include|join(',') }}
{% for db in p.db_include %}
db-include={{ db }}
{% endfor %}
{% endif %}

{% if p.link_map is defined and p.link_map is mapping and p.link_map|length > 0 %}
{% for k,v in p.link_map.items() %}
link-map={{ k }}={{ v }}
{% endfor %}
{% endif %}

[global:restore]
{% if p.process is defined and p.process is number and p.process > 0 %}
process-max={{ p.process }}
{% else %}
process-max={{ node_cpu|default(4)|int }}
{% endif %}

[global:archive-get]
process-max={{ node_cpu|default(4)|int }}
