57

PostgreSQL Disaster Recovery with Barman

Embed Size (px)

Citation preview

Page 1: PostgreSQL Disaster Recovery with Barman
Page 2: PostgreSQL Disaster Recovery with Barman

GABRIELE BARTOLINIPGDay Australia 2013 - Melbourne, 4 February 2013

Page 3: PostgreSQL Disaster Recovery with Barman

GABRIELE BARTOLINI

• Co-Founder and Manager of 2ndQuadrant Italia

• Data Architect, Business critical environments

• Data warehousing

• Co-Founder Italian PostgreSQL Users Group

• Co-Founder PostgreSQL Europe

• PostgreSQL Contributor and Advocate

Page 4: PostgreSQL Disaster Recovery with Barman

DISCLAIMERThis talk assumes you are familiar with disaster

recovery concepts and PostgreSQL implementation of Point In Time Recovery

Page 5: PostgreSQL Disaster Recovery with Barman

BE AWAREIn 2ndQuadrant, all these concepts usually fit in a 2 day workshop on Disaster Recovery and a 1 day

workshop on Barman alone

Page 6: PostgreSQL Disaster Recovery with Barman

OUTLINE

• Business continuity / Disaster recovery for databases

• Disaster recovery with Barman for PostgreSQL

Page 8: PostgreSQL Disaster Recovery with Barman

BUSINESS CONTINUITYactivity performed by an organization to ensure that critical business functions will be available to customers, suppliers,

regulators, and other entities that must have access to those functions - Wikipedia

Page 10: PostgreSQL Disaster Recovery with Barman

LAW REQUIREMENTSIn Italy, the “Codice dell’Amministrazione Digitale” defines business continuity requirements for public

administrations

Page 15: PostgreSQL Disaster Recovery with Barman

“Plans are worthless, but planning is everything. There is a very great distinction

because when you are planning for an emergency you must start with this one thing: the very definition

of "emergency" is that it is unexpected, therefore it is not going to happen the way you are

planning.”- Dwight D. Eisenhower

Page 18: PostgreSQL Disaster Recovery with Barman

REQUIREMENTS

• Automated backups

• Notifications (anomalies)

• Frequency of backups

• Retention policies

• Data protection

• Availability for recovery

Page 19: PostgreSQL Disaster Recovery with Barman

POSTGRES BACKUP

• Hot backup

• MVCC

• Logical Backup

• pg_dump

• Physical Backup

• Full backup (base backup)

• Differential backup (WAL)

Page 20: PostgreSQL Disaster Recovery with Barman

TRADITIONAL DRWITH POSTGRESQL

• PostgreSQL primitives for DR are robust and reliable

• High level skills

• DBA

• Sysadmins

• Custom scripts

• Hard to integrate in:

• Backup solutions

• Disaster Recovery plans

• Hard to test!

Page 21: PostgreSQL Disaster Recovery with Barman

EXISTING TOOLS

• Omni-PITR

• WAL centric

• WALmgr

• WAL centric

• pg-rman

• Server centric

• WAL-E

• EC2 centric, but ...

• good

• came later

Page 22: PostgreSQL Disaster Recovery with Barman

NONE FOR DRNone of them was a pure disaster recovery solution.

We wanted something similar to Oracle’s RMAN.

Page 23: PostgreSQL Disaster Recovery with Barman

FILLING A HOLEThe lack of a DR solution is a barrier towards the adoption

of PostgreSQL from Oracle users’ point of view.

Page 24: PostgreSQL Disaster Recovery with Barman

DESIDERATA

• Hot, Full, Differential and Incremental backups

• Multiple servers

• Remote backup & recovery

• Backup catalogues

• Retention policies

• Archival and compression

• WAL segments

• Periodical backups

• Automation

• Integration

• Usability

Page 27: PostgreSQL Disaster Recovery with Barman

BARMAN

• GNU GPL 3

• Hosted on Sourceforge.net

• Python 2.6/2.7

• PostgreSQL 8.4, 9.0, 9.1, 9.2

• PyPI package

• RPM package

• Debian/Ubuntu package

• Designed, developed, maintained by 2ndQuadrant

Page 28: PostgreSQL Disaster Recovery with Barman

Postgres Postgres Postgres

Barman

LAN, centralised architecture

Barman

LAN, hybrid architecture

tape

Page 29: PostgreSQL Disaster Recovery with Barman

Postgres

Barman

Continuous archiving(WAL shipping via SSH)

SSH commandsSQL commands

Page 30: PostgreSQL Disaster Recovery with Barman

secure channel

Postgres Barman

WAL cron

Barman’sWAL archive

Page 31: PostgreSQL Disaster Recovery with Barman

Postgres

Full backup - Sat 1, 4AM

Full backup - Sat 8, 4AM

Full backup - Sat 15, 4AM

Full backup - Sat 22, 4AM

Barman

Periodical backup (weekly)Differential backupBackup catalogue

Page 32: PostgreSQL Disaster Recovery with Barman

WAL WAL WAL WAL WALWAL WAL WAL WAL WAL

Backup 1

(100MB)

WAL archive

WAL WAL WAL WAL WAL

Backup 2

(105MB)

Size: 100MB + 80MB = 180MB Size: 105MB + 80MB = 185MBSize: 100MB + 160MB = 260MB

Page 33: PostgreSQL Disaster Recovery with Barman

CONFIGURATION FILE

[barman]barman_home = /srv/barmanbarman_user = barmanlog_file = /var/log/barman/barman.loglog_level = NOTICEcompression = gzip

[production]description = Production PostgreSQLssh_command = ssh pg.2ndQuadrant.itconninfo = host=pg.2ndQuadrant.it user=postgrescompression = bzip2

Page 34: PostgreSQL Disaster Recovery with Barman

MULTI-SERVER CONFIGURATION

[barman]; General configuration; …[server_one]; Configuration for Server 1; …[server_two]; Configuration for Server 2; …[server_X]; …

Page 35: PostgreSQL Disaster Recovery with Barman

MULTIPLE FILES INCLUSION

[barman]; General configuration; …configuration_files_directory = /etc/barman.d

Page 36: PostgreSQL Disaster Recovery with Barman

CONVENTION OVER CONFIGURATION

global/per server optionsdefault directory layout

Page 37: PostgreSQL Disaster Recovery with Barman

CONVENTIONAL DIRECTORIES FOR BARMAN

• barman_home (/srv/barman)

• server directory (/srv/barman/production)

• base directory (/srv/barman/production/base)

• WAL directory (/srv/barman/production/wals)

• incoming directory (/srv/barman/production/incoming)

Page 38: PostgreSQL Disaster Recovery with Barman

GLOBAL COMMANDS

• List of managed servers

• barman list-server

• Maintenance operations

• barman cron

Page 39: PostgreSQL Disaster Recovery with Barman

SERVER COMMANDS

• Information and diagnostics

• barman status

• barman check

• barman show-server

• barman list-backup

• Backup control

• Recovery control

Page 40: PostgreSQL Disaster Recovery with Barman
Page 41: PostgreSQL Disaster Recovery with Barman

BACKUP CONTROL

• barman backup

• barman show-backup

• barman list-files

• standalone, data, wal, full

• barman delete

Page 42: PostgreSQL Disaster Recovery with Barman
Page 43: PostgreSQL Disaster Recovery with Barman

SHOW BACKUP

• General

• Server name, Postgres version, status, ...

• Base backup

• Start/End time, first/last WAL, disk usage, ...

• WAL

• Number of associated files

• disk usage

• Context

• Previous/Next backup

Page 44: PostgreSQL Disaster Recovery with Barman
Page 45: PostgreSQL Disaster Recovery with Barman

RECOVERY CONTROL

• Recovery target (full / point in time)

• Local recovery

• barman recover

• Remote recovery

• barman recover --remote-ssh-command

Page 46: PostgreSQL Disaster Recovery with Barman

ADVANCED RECOVERY

• Point In Time Recovery

• --target-time = TIME

• --target-xid = XID

• Relocation of tablespaces

• --tablespace NAME:LOCATION [...]

Page 47: PostgreSQL Disaster Recovery with Barman

COMMON USE CASES

• Accidental errors recovery

• Disaster recovery

• Sandbox server (BI, staging, ...)

Page 48: PostgreSQL Disaster Recovery with Barman
Page 49: PostgreSQL Disaster Recovery with Barman

RETENTION POLICIES

• User-defined policy

• Determines how long backups and related WAL files need to be retained for recovery procedures (point of recoverability):

• based on number of backups (REDUNDANCY) or time (RECOVERY WINDOW)

• Currently implemented only in auto mode

• through ‘barman cron’

Page 50: PostgreSQL Disaster Recovery with Barman

RETENTION POLICY CONFIGURATION

; Base backup retention policyretention_policy = 'redundancy 3'retention_policy = 'recovery window of 3 months'

; WAL retention policywal_retention_policy = 'base'; The following is currently not supportedwal_retention_policy = 'recovery window of 14 days'

Page 51: PostgreSQL Disaster Recovery with Barman

SPONSOR A FEATURE!

• Sandbox recovery

• Export/Import

• Logical backup integration

• pg_dump on sandbox instances

• Replication protocol support (client / server)

• Incremental backup

• reduce backup time and size

Page 52: PostgreSQL Disaster Recovery with Barman

OUR COMMITMENT

• Keep it open source

• Reinvest money from sale of DR turnkey solutions in R&D

• Support and maintain RPM/Debian packages

• Accept sponsorships for new features development

Page 53: PostgreSQL Disaster Recovery with Barman

CSI PIEMONTE

(One of the top 10 ICT companies in Italy for revenue)

“We found in Barman the optimal solution for physical backup and disaster recovery of PostgreSQL databases. Barman is

robust and easy to use. Its command interface allows an easy integration with the existing management tools in our

enviroment.”

Sponsors of RPM package and WAL compression

Page 54: PostgreSQL Disaster Recovery with Barman

CONCLUSIONS

• Hides complexity of PITR / Keeps unaltered PITR strenghts

• Not invasive

• Fosters migrations from Oracle

• “Standard de facto” for PostgreSQL Disaster Recovery

• Advice: plan for DR (if you have not done it yet)

Page 55: PostgreSQL Disaster Recovery with Barman

QUESTIONS?

[email protected] : _GBartolini_www.pgbarman.org

Page 56: PostgreSQL Disaster Recovery with Barman

THANK YOU!

Page 57: PostgreSQL Disaster Recovery with Barman

LICENSE

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Copyright (c) 2012, 2013 - 2ndQuadrant.it