()

Physical PostgreSQL Backup using BARMAN

In the previous blog, we have demonstrated Install & Configured barman tool in Backup Server Click here to read more
In this blog, we will use barman tool to take database backups.  


List available servers: Use command barman list-server to get the list configured server in barman.

-bash-4.2$ barman list-server
test-machine02 - test-machine02 backup config
-bash-4.2$


Show configured parameters: Use command barman show-server to list down all configured parameters for the specified server.

-bash-4.2$ barman show-server test-machine02
Server test-machine02:
        active: True
        archive_command: test ! -f barman@test-machine01:/var/lib/barman/test-machine02/incoming/%f && rsync -a %p barman@test-machine01:/var/lib/barman/test-machine02/incoming/%f
        archive_mode: on
        archive_timeout: 21600
        archived_count: 67
        archiver: True
        archiver_batch_size: 0
        backup_directory: /var/lib/barman/test-machine02
        backup_method: rsync
        backup_options: BackupOptions(['concurrent_backup'])
        bandwidth_limit: None
        barman_home: /var/lib/barman
        barman_lock_directory: /var/lib/barman
        basebackup_retry_sleep: 30
        basebackup_retry_times: 3
        basebackups_directory: /var/lib/barman/test-machine02/base
        check_timeout: 30
        checkpoint_timeout: 300
        compression: gzip
        config_file: /var/lib/pgsql/13/data/postgresql.conf
        conninfo: host=test-machine02 user=barman port=5432 dbname=postgres password=*REDACTED* create_slot: manual


Check server configuration: Use command barman check to confirm all server configuration is OK.

-bash-4.2$ barman check test-machine02
Server test-machine02:
        PostgreSQL: OK
        superuser or standard user with backup privileges: OK
        wal_level: OK
        directories: OK
        retention policy settings: OK
        backup maximum age: OK (no last_backup_maximum_age provided)
        compression settings: OK
        failed backups: OK (there are 0 failed backups)
        minimum redundancy requirements: OK (have 3 backups, expected at least 0)
        ssh: OK (PostgreSQL server)
        systemid coherence: OK
        archive_mode: OK
        archive_command: OK
        continuous archiving: OK
        archiver errors: OK
-bash-4.2$


Help Command: Use option –help to get all available options for barman.

-bash-4.2$ barman --help
usage: barman [-h] [-v] [-c CONFIG] [--color {never,always,auto}]
              [--log-level {NOTSET,DEBUG,INFO,WARNING,ERROR,CRITICAL}] [-q]
              [-d] [-f {json,console}]

              {archive-wal,backup,check,check-backup,cron,delete,diagnose,get-wal,list-backup,list-files,list-server,put-wal,rebuild-xlogdb,receive-wal,recover,show-backup,show-server,replication-status,status,switch-wal,switch-xlog,sync-info,sync-backup,sync-wals}
              ...

positional arguments:
  {archive-wal,backup,check,check-backup,cron,delete,diagnose,get-wal,list-backup,list-files,list-server,put-wal,rebuild-xlogdb,receive-wal,recover,show-backup,show-server,replication-status,status,switch-wal,switch-xlog,sync-info,sync-backup,sync-wals}
    archive-wal         Execute maintenance operations on WAL files for a
                        given server. This command processes any incoming WAL
                        files for the server and archives them along the
                        catalogue.
    backup              Perform a full backup for the given server (supports
                        'all')


Help for Specific Command: Use barman <command> –help to get full available options that specific command.

-bash-4.2$ barman backup --help
usage: barman backup [-h] [--immediate-checkpoint] [--no-immediate-checkpoint]
                     [--reuse-backup [{copy,link,off}]]
                     [--retry-times RETRY_TIMES] [--retry-sleep RETRY_SLEEP]
                     [--no-retry] [--jobs NJOBS] [--bwlimit KBPS] [--wait]
                     [--wait-timeout TIMEOUT]
                     server_name [server_name ...]

    Perform a full backup for the given server (supports 'all')


positional arguments:
  server_name           specifies the server names for the backup command
                        ('all' will show all available servers)

optional arguments:
  -h, --help            show this help message and exit
  --immediate-checkpoint
                        forces the initial checkpoint to be done as quickly as
                        possible


Full Database Backup: Use command barman backup to take full database backup of specific Server.

-bash-4.2$ barman backup test-machine02
Starting backup using rsync-concurrent method for server test-machine02 in /var/lib/barman/test-machine02/base/20210622T153402
Backup start at LSN: 0/32000028 (000000010000000000000032, 00000028)
This is the first backup for server test-machine02
WAL segments preceding the current backup have been found:
        000000010000000000000030 from server test-machine02 has been removed
        000000010000000000000030.00000060.backup from server test-machine02 has been removed
Starting backup copy via rsync/SSH for 20210622T153402
Copy done (time: 3 seconds)
This is the first backup for server test-machine02
Asking PostgreSQL server to finalize the backup.
Backup size: 46.8 MiB. Actual size on disk: 46.8 MiB (-0.00% deduplication ratio).
Backup end at LSN: 0/32000138 (000000010000000000000032, 00000138)
Backup completed (start time: 2021-06-22 15:34:03.046194, elapsed time: 6 seconds)
Processing xlog segments from file archival for test-machine02
        000000010000000000000031
        000000010000000000000032
        000000010000000000000032.00000028.backup
-bash-4.2$


Full Database Backup: You can also take full database backup using the below command as well.

-bash-4.2$ barman backup test-machine02 --reuse-backup=off
Starting backup using rsync-concurrent method for server test-machine02 in /var/lib/barman/test-machine02/base/20210623T143656
Backup start at LSN: 0/34000028 (000000010000000000000034, 00000028)
Starting backup copy via rsync/SSH for 20210623T143656
Copy done (time: 3 seconds)
Asking PostgreSQL server to finalize the backup.
Backup size: 46.8 MiB
Backup end at LSN: 0/34000100 (000000010000000000000034, 00000100)
Backup completed (start time: 2021-06-23 14:36:56.282179, elapsed time: 7 seconds)
Processing xlog segments from file archival for test-machine02
        000000010000000000000034
        000000010000000000000034.00000028.backup
-bash-4.2$
-bash-4.2$


Incremental Database Backup: Use option –reuse-backup=link along with barman backup command to take incremental backup of the database.

-bash-4.2$ barman backup test-machine02 --reuse-backup=link 
Starting backup using rsync-concurrent method for server test-machine02 in /var/lib/barman/test-machine02/base/20210623T154948
Backup start at LSN: 0/36000028 (000000010000000000000036, 00000028)
Starting backup copy via rsync/SSH for 20210623T154948
Copy done (time: 1 second)
Asking PostgreSQL server to finalize the backup.
Backup size: 46.8 MiB. Actual size on disk: 9.8 KiB (-99.98% deduplication ratio).
Backup end at LSN: 0/36000100 (000000010000000000000036, 00000100)
Backup completed (start time: 2021-06-23 15:49:49.106786, elapsed time: 6 seconds)
Processing xlog segments from file archival for test-machine02
        000000010000000000000035
        000000010000000000000036
        000000010000000000000036.00000028.backup
-bash-4.2$
-bash-4.2$


List available backup: Use command barman list-backup to list all available backups of the specific server.

-bash-4.2$ barman list-backup test-machine02
test-machine02 20210623T154948 - Wed Jun 23 15:49:57 2021 - Size: 46.9 MiB - WAL Size: 0 B (tablespaces: myts01:/u01/psql_tbls, myts02:/u01/psql2_tbls)
test-machine02 20210623T143656 - Wed Jun 23 14:37:06 2021 - Size: 46.9 MiB - WAL Size: 32.3 KiB (tablespaces: myts01:/u01/psql_tbls, myts02:/u01/psql2_tbls)
test-machine02 20210622T153402 - Tue Jun 22 15:34:12 2021 - Size: 46.9 MiB - WAL Size: 32.3 KiB (tablespaces: myts01:/u01/psql_tbls, myts02:/u01/psql2_tbls)
test-machine02 20210622T153129 - FAILED
-bash-4.2$


Detailed Information of specific Backup: Use command barman show-backup to get detailed information of specific backup.

-bash-4.2$ barman show-backup test-machine02 20210623T154948
Backup 20210623T154948:
  Server Name            : test-machine02
  System Id              : 6955437016975533153
  Status                 : DONE
  PostgreSQL Version     : 130002
  PGDATA directory       : /var/lib/pgsql/13/data
  Tablespaces:
    myts01: /u01/psql_tbls (oid: 23701)
    myts02: /u01/psql2_tbls (oid: 23704)

  Base backup information:
    Disk usage           : 46.8 MiB (46.9 MiB with WALs)
    Incremental size     : 9.8 KiB (-99.98%)
    Timeline             : 1
    Begin WAL            : 000000010000000000000036
    End WAL              : 000000010000000000000036
    WAL number           : 1
    WAL compression ratio: 99.90%
    Begin time           : 2021-06-23 15:49:52.521603+03:00
    End time             : 2021-06-23 15:49:57.173958+03:00
    Copy time            : 1 second + 1 second startup
    Estimated throughput : 5.3 KiB/s
    Begin Offset         : 40
    End Offset           : 256
    Begin LSN           : 0/36000028
    End LSN             : 0/36000100

  WAL information:
    No of files          : 0
    Disk usage           : 0 B
    Last available       : 000000010000000000000036

  Catalog information:
    Retention Policy     : not enforced
    Previous Backup      : 20210623T143656
    Next Backup          : - (this is the latest base backup)
-bash-4.2$


WAL only Backup: Use command barman archive-wal to take the only backup of WAL Files.

-bash-4.2$ barman archive-wal test-machine02 
Processing xlog segments from file archival for test-machine02
        000000010000000000000037
        000000010000000000000038
-bash-4.2$


Delete backup: Use command barman delete to delete specific backup files.

-bash-4.2$ barman delete test-machine02 20210622T153129
Deleting backup 20210622T153129 for server test-machine02
Delete associated WAL segments:
Deleted backup 20210622T153129 (start time: Wed Jun 23 17:12:08 2021, elapsed time: less than one second)
-bash-4.2$

 

This document is just for learning purpose and always validate in the LAB environment first before applying in the LIVE environment.


Hope so you like this article
!
Please share your valuable feedback/comments/subscribe and follow us below and don’t forget to click on the bell icon to get the most recent update. Click here to understand more about our pursuit.

Related Articles


Loading

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Jamsher Khan

Hello and welcome to DBsGuru,I’m Jamsher Khan working as Senior Oracle DBA based in KSA-Jeddah, I have working experience in Oracle DBA, SQL Server, MySql, PostgreSQL, Linux, Golden Gate, ODA.Thanks for the visits!Share Learn Grow!