Friday , November 22 2024

Streaming Backup with PostgreSQL Barman

What is Barman?

Barman is an open source backup / restore management tool in PostgreSQL.

What can you do with Barman?

  • You can create backups on the same server.
  • You can create a backup to a different backup server.
  • You can create multiple PostgreSQL cluster backups.
  • You can back up multiple PostgreSQL Clusters running in different major versions of PostgreSQL. So you can collect your backups on a central backup server.
  • With Barman, you can create backups in 2 different ways:
    -rsync / ssh
    -streaming

In this article, we will create a backup to the / pg_backup directory on the PostgreSQL server.

Barman Installation

For Debian and Derivatives:

For Redhat and Derivatives:

Configure PostgreSQL For Barman

In PostgreSQL, create the barman user with the superuser right for backup operations and the streaming_barman user with the replication right for streaming operations.

Or by connecting with psql, we can create it as follows:

We edit the pg_hba.conf file so that the user can connect to the database.

PostgreSQL service requires reload operation for a change in the pg_hba.conf file to take effect. By connecting with psql, we can do it with the following command.

We can check the access of the barman user we created with the command below.

We can check the access of the streaming_barman user as follows.

Configure Barman

Barman has 2 types of configuration files:

  • barman.conf
  • barman.d

/etc/barman.conf -> It is a global configuration file. It contains general backup configurations such as log file, backup user, backup directory.

Edit the barman.conf file as follows:

/etc/barman.d ->Server configuration files are located under /etc/barman.d directory by default. Template configuration files are available under this directory for the backup methods(streaming and rsync).

You can create a configuration file for each PostgreSQL cluster you want to backup with Barman using these template files.

First of all, copy the streaming-server.conf-template file from the template files with the name of the cluster data directory and edit the file.

We create slots with the command of Barman:

To check the streaming settings of WAL files;

Check Barman Configuration

You can check the Barman configuration as follows.

Barman Create Backup

You can create the first backup with the following command.

You can check the general status of the server as follows.

Barman Restore

Restore PostgreSQL Cluster With Barman

You can recover the backup to a directory on the server accessible by the barman user as follows.

Barman Point in Time Recovery

For Point in Time Restore, we can specify the time with the target-time parameter.

In this article I mentioned backup with basic level configurations. For more detailed information, you can use the barman’s web page, https://www.pgbarman.org/.

Loading

About Zekiye AYDEMİR

2 comments

  1. Hi,

    After the below section , there is no content about what you have edited in the streaming-server.conf file. Plz help

    First of all, copy the streaming-server.conf-template file from the template files with the name of the cluster data directory and edit the file.

  2. Don’t forget to add/enable in
    postgres.conf
    listen_addresses= ‘…’
    if you’re going to do use barmat from a remote machine (as is recommended)!
    Took me an hour to figure that out

Leave a Reply

Your email address will not be published. Required fields are marked *