2ndQuadrant is now part of EDB

Bringing together some of the world's top PostgreSQL experts.

2ndQuadrant | PostgreSQL
Mission Critical Databases
  • Contact us
  • EN
    • FR
    • IT
    • ES
    • DE
    • PT
  • Support & Services
  • Products
  • Downloads
    • Installers
      • Postgres Installer
      • 2UDA – Unified Data Analytics
    • Whitepapers
      • Business Case for PostgreSQL Support
      • Security Best Practices for PostgreSQL
    • Case Studies
      • Performance Tuning
        • BenchPrep
        • tastyworks
      • Distributed Clusters
        • ClickUp
        • European Space Agency (ESA)
        • Telefónica del Sur
        • Animal Logic
      • Database Administration
        • Agilis Systems
      • Professional Training
        • Met Office
        • London & Partners
      • Database Upgrades
        • Alfred Wegener Institute (AWI)
      • Database Migration
        • International Game Technology (IGT)
        • Healthcare Software Solutions (HSS)
        • Navionics
  • Postgres Learning Center
    • Webinars
      • Upcoming Webinars
      • Webinar Library
    • Whitepapers
      • Business Case for PostgreSQL Support
      • Security Best Practices for PostgreSQL
    • Blog
    • Training
      • Course Catalogue
    • Case Studies
      • Performance Tuning
        • BenchPrep
        • tastyworks
      • Distributed Clusters
        • ClickUp
        • European Space Agency (ESA)
        • Telefónica del Sur
        • Animal Logic
      • Database Administration
        • Agilis Systems
      • Professional Training
        • Met Office
        • London & Partners
      • Database Upgrades
        • Alfred Wegener Institute (AWI)
      • Database Migration
        • International Game Technology (IGT)
        • Healthcare Software Solutions (HSS)
        • Navionics
    • Books
      • PostgreSQL 11 Administration Cookbook
      • PostgreSQL 10 Administration Cookbook
      • PostgreSQL High Availability Cookbook – 2nd Edition
      • PostgreSQL 9 Administration Cookbook – 3rd Edition
      • PostgreSQL Server Programming Cookbook – 2nd Edition
      • PostgreSQL 9 Cookbook – Chinese Edition
    • Videos
    • Events
    • PostgreSQL
      • PostgreSQL – History
      • Who uses PostgreSQL?
      • PostgreSQL FAQ
      • PostgreSQL vs MySQL
      • The Business Case for PostgreSQL
      • Security Information
      • Documentation
  • About Us
    • About 2ndQuadrant
    • 2ndQuadrant’s Passion for PostgreSQL
    • News
    • Careers
    • Team Profile
  • Blog
  • Menu Menu
You are here: Home1 / Blog2 / 2ndQuadrant3 / Barman Cloud – Part 2: Cloud Backup
Anna Bellandi

Barman Cloud – Part 2: Cloud Backup

July 16, 2020/0 Comments/in 2ndQuadrant, Anna's PlanetPostgreSQL, Barman, DevOps, PostgreSQL /by Anna Bellandi

In the first part of this blog, Jonathan explained how the barman-wal-archive command works. Now, assuming you followed those instructions, you have a properly configured PostgreSQL instance up and running. In this second part, I will show you how the barman-cloud-backup command works.


As you can guess from the command name itself, the barman-cloud-backup command allows you to execute backups directly from a PostgreSQL server and use an S3 compatible object store in the Cloud as destination.

[email protected]:~ $ barman-cloud-backup --help
usage: barman-cloud-backup [-V] [--help] [-v | -q] [-P PROFILE] [-z | -j]
                           [-e {AES256,aws:kms}] [-t] [-h HOST] [-p PORT]
                           [-U USER] [--immediate-checkpoint] [-J JOBS]
                           [-S MAX_ARCHIVE_SIZE] [--endpoint-url ENDPOINT_URL]
                           destination_url server_name

This script can be used to perform a backup of a local PostgreSQL instance and
ship the resulting tarball(s) to the Cloud. Currently only AWS S3 is supported.

positional arguments:
  destination_url       URL of the cloud destination, such as a bucket in AWS
                        S3. For example: `s3://bucket/path/to/folder`.
  server_name           the name of the server as configured in Barman.

optional arguments:
  -V, --version         show program's version number and exit
  --help                show this help message and exit
  -v, --verbose         increase output verbosity (e.g., -vv is more than -v)
  -q, --quiet           decrease output verbosity (e.g., -qq is less than -q)
  -P PROFILE, --profile PROFILE
                        profile name (e.g. INI section in AWS credentials
                        file)
  -z, --gzip            gzip-compress the WAL while uploading to the cloud
  -j, --bzip2           bzip2-compress the WAL while uploading to the cloud
  -e {AES256,aws:kms}, --encryption {AES256,aws:kms}
                        Enable server-side encryption for the transfer.
                        Allowed values: 'AES256'|'aws:kms'.
  -t, --test            Test cloud connectivity and exit
  -h HOST, --host HOST  host or Unix socket for PostgreSQL connection
                        (default: libpq settings)
  -p PORT, --port PORT  port for PostgreSQL connection (default: libpq
                        settings)
  -U USER, --user USER  user name for PostgreSQL connection (default: libpq
                        settings)
  --immediate-checkpoint
                        forces the initial checkpoint to be done as quickly as
                        possible
  -J JOBS, --jobs JOBS  number of subprocesses to upload data to S3 (default:
                        2)
  -S MAX_ARCHIVE_SIZE, --max-archive-size MAX_ARCHIVE_SIZE
                        maximum size of an archive when uploading to S3
                        (default: 100GB)
  --endpoint-url ENDPOINT_URL
                        Override default S3 endpoint URL with the given one

Now that we have a clearer idea of the command and its options, we are ready to execute our first cloud backup:

[email protected]:~ $ barman-cloud-backup -P barman-cloud \
  -e AES256 -j --immediate-checkpoint -J 4 \
  s3://barman-s3-test/ pg12

Once the backup has been completed successfully, the base directory containing the backup will be in your S3 bucket. Let’s check it, building the destination path with the server name and the base directory:

[email protected]:~ $ aws s3 --profile barman-cloud ls s3://barman-s3-test/pg12/base/
                           PRE 20200713T120856/

Alternatively, you can use barman-cloud-backup-list, but in this article I would like to focus on the mechanics behind it.

The 20200711T092548 directory contains all files related to the backup that we have just executed. Let’s look at its contents:

[email protected]:~ $ aws s3 --profile barman-cloud ls s3://barman-s3-test/pg12/base/20200713T120856/
2020-07-13 12:09:08       1138 backup.info
2020-07-13 12:09:07    9263096 data.tar.bz2

As we can see, there is a compressed and encrypted file containing our backup (data.tar.bz2) and a file called backup.info containing the information related to the backup. We can restore the backup by copying and unzipping the data.tar.bz2 file on our local server as shown below:

[email protected]:~ $ aws s3 --profile barman-cloud cp s3://barman-s3-test/pg12/base/20200713T120856/data.tar.bz2 restore-dir
download: s3://barman-s3-test/pg12/base/20200713T120856/data.tar.bz2 to restore-dir/data.tar.bz2

[email protected]:~ $ cd restore-dir

[email protected]:~/restore-dir $ tar xjvf data.tar.bz2

[email protected]:~/restore-dir $ ls
PG_VERSION    conf.d        pg_commit_ts  pg_ident.conf  pg_notify    pg_snapshots  pg_subtrans  pg_wal                postgresql.conf
backup_label  data.tar.bz2  pg_dynshmem   pg_logical     pg_replslot  pg_stat       pg_tblspc    pg_xact
base          global        pg_hba.conf   pg_multixact   pg_serial    pg_stat_tmp   pg_twophase  postgresql.auto.conf

Great! As we can see, all the files in the DATADIR of the PostgreSQL instance that we backed up, including the configuration files, are listed correctly here.

Conclusions

With the barman-cloud-backup command Barman introduces an important feature that allows you to execute and directly ship base backups from a local PostgreSQL server to cloud object storage services that are compatible with AWS S3 in just a few simple steps. It supports encryption, parallel upload, compression, and allows to save disk space on your local server and transfer safely the backups to the cloud.

With the release of Barman 2.11, which happened a few days ago, important new features have been introduced, including the barman-cloud-wal-restore and the barman-cloud-restore commands, which allow to retrieve the backup and WAL files from an object store such as AWS S3. In that regard, we will publish a new blog article soon explaining how to prepare the recovery of a PostgreSQL instance using these commands. Stay tuned.

Tags: Amazon S3, AWS, backup, Barman, cloud, disaster recovery, pgbarman, PostgreSQL
Share this entry
  • Share on Facebook
  • Share on Twitter
  • Share on WhatsApp
  • Share on LinkedIn
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

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

Search

Get in touch with us!

Recent Posts

  • Random Data December 3, 2020
  • Webinar: COMMIT Without Fear – The Beauty of CAMO [Follow Up] November 13, 2020
  • Full-text search since PostgreSQL 8.3 November 5, 2020
  • Random numbers November 3, 2020
  • Webinar: Best Practices for Bulk Data Loading in PostgreSQL [Follow Up] November 2, 2020

Featured External Blogs

Tomas Vondra's Blog

Our Bloggers

  • Simon Riggs
  • Alvaro Herrera
  • Andrew Dunstan
  • Craig Ringer
  • Francesco Canovai
  • Gabriele Bartolini
  • Giulio Calacoci
  • Ian Barwick
  • Marco Nenciarini
  • Mark Wong
  • Pavan Deolasee
  • Petr Jelinek
  • Shaun Thomas
  • Tomas Vondra
  • Umair Shahid

PostgreSQL Cloud

2QLovesPG 2UDA 9.6 backup Barman BDR Business Continuity community conference database DBA development devops disaster recovery greenplum Hot Standby JSON JSONB logical replication monitoring OmniDB open source Orange performance PG12 pgbarman pglogical PG Phriday postgres Postgres-BDR postgres-xl PostgreSQL PostgreSQL 9.6 PostgreSQL10 PostgreSQL11 PostgreSQL 11 PostgreSQL 11 New Features postgresql repmgr Recovery replication security sql wal webinar webinars

Support & Services

24/7 Production Support

Developer Support

Remote DBA for PostgreSQL

PostgreSQL Database Monitoring

PostgreSQL Health Check

PostgreSQL Performance Tuning

Database Security Audit

Upgrade PostgreSQL

PostgreSQL Migration Assessment

Migrate from Oracle to PostgreSQL

Products

HA Postgres Clusters

Postgres-BDR®

2ndQPostgres

pglogical

repmgr

Barman

Postgres Cloud Manager

SQL Firewall

Postgres-XL

OmniDB

Postgres Installer

2UDA

Postgres Learning Center

Introducing Postgres

Blog

Webinars

Books

Videos

Training

Case Studies

Events

About Us

About 2ndQuadrant

What does 2ndQuadrant Mean?

News

Careers 

Team Profile

© 2ndQuadrant Ltd. All rights reserved. | Privacy Policy
  • Twitter
  • LinkedIn
  • Facebook
  • Youtube
  • Mail
Fireside Chat: BDR – Advanced Clustering & Scaling for PostgreSQL... Fireside Chat: BDR - Advanced Clustering & Scaling for PostgreSQL Webinar: Enhancing Postgres High Availability [Follow Up]
Scroll to top
×