diff --git a/docs/replica_bootstrap.rst b/docs/replica_bootstrap.rst index 77f27e66..2d1da113 100644 --- a/docs/replica_bootstrap.rst +++ b/docs/replica_bootstrap.rst @@ -23,6 +23,7 @@ arguments to them, i.e. the name of the cluster and the path to the data directo method: : command: [param1 [, ...]] + keep_existing_recovery_conf: False recovery_conf: recovery_target_action: promote recovery_target_timeline: latest @@ -47,6 +48,9 @@ If a ``recovery_conf`` block is defined in the same section as the custom bootst ``recovery.conf`` before starting the newly bootstrapped instance. Typically, such recovery.conf should contain at least one of the ``recovery_target_*`` parameters, together with the ``recovery_target_timeline`` set to ``promote``. +If ``keep_existing_recovery_conf`` is defined and set to ``True``, Patroni will not remove the existing ``recovery.conf`` file if it exists. +This is useful when bootstrapping from a backup with tools like pgBackRest that generate the appropriate ``recovery.conf`` for you. + .. note:: Bootstrap methods are neither chained, nor fallen-back to the default one in case the primary one fails diff --git a/patroni/postgresql.py b/patroni/postgresql.py index 742e1017..a4a076d4 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -556,7 +556,8 @@ class Postgresql(object): if 'recovery_conf' in config: self.write_recovery_conf(config['recovery_conf']) - elif os.path.isfile(self._recovery_conf) or os.path.islink(self._recovery_conf): + elif (os.path.isfile(self._recovery_conf) or os.path.islink(self._recovery_conf)) and \ + not config.get('keep_existing_recovery_conf'): os.unlink(self._recovery_conf) return True