# patroni.scripts.barman.recover module

Implements `patroni_barman recover` sub-command.

Restore a Barman backup to the local node through `pg-backup-api`.

This sub-command can be used both as a custom bootstrap method, and as a custom create replica method. Check the output of `--help` to understand the parameters supported by the sub-command. `--datadir` is a special parameter and it is automatically filled by Patroni in both cases.

It requires that you have previously configured a Barman server, and that you have `pg-backup-api` configured and running in the same host as Barman.

Refer to `ExitCode` for possible exit codes of this sub-command.

class patroni.scripts.barman.recover.ExitCode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

  Bases: `IntEnum`

  Possible exit codes of this script.

  Variables:

    - RECOVERY_DONE – backup was successfully restored.

    - RECOVERY_FAILED – recovery of the backup faced an issue.

    - HTTP_ERROR – an error has occurred while communicating with `pg-backup-api`

  HTTP_ERROR = 2
  RECOVERY_DONE = 0
  RECOVERY_FAILED = 1

patroni.scripts.barman.recover._restore_backup(api: PgBackupApi, barman_server: str, backup_id: str, ssh_command: str, data_directory: str, loop_wait: int) → int

  Restore the configured Barman backup through `pg-backup-api`.

  Note

  If requests to `pg-backup-api` fail recurrently or we face HTTP errors, then exit with `ExitCode.HTTP_ERROR`.

  Parameters:

    - api – a `PgBackupApi` instance to handle communication with the API.

    - barman_server – name of the Barman server which backup is to be restored.

    - backup_id – ID of the backup from the Barman server.

    - ssh_command – SSH command to connect from the Barman host to the target host.

    - data_directory – path to the Postgres data directory where to restore the backup in.

    - loop_wait – how long in seconds to wait before checking again the status of the recovery process. Higher values are useful for backups that are expected to take longer to restore.

  Returns:

    the return code to be used when exiting the `patroni_barman` application. Refer to `ExitCode`.

patroni.scripts.barman.recover.run_barman_recover(api: PgBackupApi, args: Namespace) → int

  Run a remote `barman recover` through the `pg-backup-api`.

  Parameters:

    - api – a `PgBackupApi` instance to handle communication with the API.

    - args – arguments received from the command-line of `patroni_barman recover` command.

  Returns:

    the return code to be used when exiting the `patroni_barman` application. Refer to `ExitCode`.