Even though Barman can centrally manage backups of several servers that have different versions of PostgreSQL, when it comes to recovery, the same requirements for PostgreSQL's PITR technology apply. In particular, the following:
- You must recover on a server with the same hardware architecture and PostgreSQL version
- Recovery is full, meaning the entire Postgres cluster will be restored (and not a single database)
The use case of this recipe is the following:
- The bon server has been lost forever, due to a permanent hardware failure
- The brian server, having similar characteristics to bon, has been selected for recovery
- The same Linux distribution and PostgreSQL packages have been installed on brian
- Barman will be used to perform remote recovery of the latest backup available for bon on the brian server
In order to proceed, you need to add the public SSH key of the barman user on malcolm in the ~/.ssh/authorized_keys file of the Postgres user on brian. If you are not familiar with the process of exchanging a public SSH key, which goes beyond the scope of this book, you are advised to follow Barman's documentation or surf the net for more information.
The first step is to make sure that the PGDATA directory, as specified in the bon backup, exists on brian and can be written by the postgres user.
Ask barman for the location of PGDATA by querying the latest available backup metadata:
barman show-backup bon last
Write down the content of the PGDATA directory entry:
PGDATA directory : /var/lib/pgsql/10/data
You might have noticed that we are using the default PGDATA directory for a RHEL/CentOS cluster based on packages maintained by the PostgreSQL community. On Ubuntu, you will probably have /var/lib/postgresql/10/main.
As the second step, also make sure that PostgreSQL is not running on Brian, using either the service or pg_ctl command.
Executing a recovery operation on a target directory used by a running PostgreSQL instance will permanently damage that instance. Be extremely careful when you perform such an operation.