Backup and Recovery: Single-Server Streaming - Installing and Configuring Barman
Suggest editsIn the previous step, we configured the PostgreSQL server, creating users for Barman to connect and manage backups. In this step, we'll install and configure Barman on the backup server.
This demo is interactive
You can follow along right in your browser. When you click "Start Now," Katacoda will load a Docker Compose
environment with two container images representing a PostgreSQL 13 server with
the Pagila database loaded (named pg
)
and a backup server for Barman (named backup
).
Once you see a root@backup
prompt, you can follow the steps below.
This demonstration uses an Ubuntu environment, so the first step is to configure the PostgreSQL repository (details are on the PostgreSQL wiki)
Install prerequesite software
Add PostgreSQL's authentication key
Add the PostgreSQL repository to the list of sources, and update available packages
With the repository configured, we can use apt to install Barman and its dependencies:
Further reading
For more details on installation (including instructions for other supported operating systems), see the Installation section in the Barman guide.
Configuration
All the important details for a Barman server go into a server configuration file, by default located in /etc/barman.d
. These are in the classic INI format, with relevant settings in a section named after the server we're going to back up. We'll also use that name for the configuration file itself. Since the server we intend to back up is named "pg", we'll use that:
Note that this references the users (barman
and streaming_barman
) that we created in step #1 - Database Server Configuration. Also of interest is the value for slot_name
- this is a replication slot that will also have to be created on the server - but we can instruct Barman to do that for us by setting create_slot
to auto
.
The installation process created a brand-new barman user on the backup server, so let's switch to that for the rest of this:
PostgreSQL Connection Password File
In order for Barman to connect via the user specified, we'll need to add the password we specified in the previous step to Barman's .pgpass file:
Each line in the .pgpass
file needs to follow below format:
The database name [db_name] for the barman streaming user must be replication
Note the change in permissions - this is necessary to protect the visibility of the file. PostgreSQL won't use it unless permissions are restricted.
Further reading
For more details on configuration files, see: the Configuration section in the Barman guide.
Verifying the configuration
During installation, Barman will have installed a cron service that runs every minute to maintenance tasks. Since we only just gave it a configuration, let's make sure those tasks have run before continuing:
Now that the configuration is done and initialization has been performed, we can use Barman's check command to verify that it works:
Uh-oh! WAL archive failed? Not a problem - that just means Barman hasn't seen any new WAL archives come in yet, which isn't surprising given this is an example database with no writes happening! We can trigger an archive manually and verify that this works:
This forces WAL rotation and (with the --archive
option) waits for the WAL to arrive. We'll give it 60 seconds (with the --archive-timeout
option) to complete;
if it doesn't complete within that amount of time, try again. For more detail on these commands and their options, refer to the Barman manual.
Once switch-wal has completed successfully, run the check again and you should see all checks passing:
Continue on with Step #3: Running Backups.
- On this page
- Configuration
Could this page be better? Report a problem or suggest an addition!