postgresql disaster recovery with barman (pgconf.eu 2013)
DESCRIPTION
Are you tired of managing backup and recovery processes of your Postgres server using custom scripts? Are you worried about being called in the night or worse whilst on holiday to perform a recovery operation of your company's business critical PostgreSQL server? Barman, Backup and Recovery Manager, standardises backup and recovery operations, allowing database administrators and system administrators to easily integrate their PostgreSQL solutions in their disaster recovery plan. Barman is distributed as open source under GNU GPL 3 terms. Further information available at www.pgbarman.org.TRANSCRIPT
![Page 1: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/1.jpg)
COLD SWEAT
![Page 2: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/2.jpg)
![Page 3: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/3.jpg)
![Page 4: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/4.jpg)
GABRIELE BARTOLINIPGConf.EU 2013 - Dublin, 30 October 2013
![Page 5: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/5.jpg)
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 6: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/6.jpg)
DISCLAIMERThis talk assumes you are familiar with disaster
recovery concepts and PostgreSQL implementation of Point In Time Recovery
![Page 7: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/7.jpg)
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 8: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/8.jpg)
OUTLINE
• Business continuity / Disaster recovery for databases
•Disaster recovery with Barman for PostgreSQL
![Page 9: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/9.jpg)
PART IBusiness continuity / Disaster recovery for databases
![Page 10: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/10.jpg)
BUSINESS CONTINUITYactivity performed by an organisation 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 11: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/11.jpg)
INFORMATION TECHNOLOGY
• Business continuity
• High availability
• Disaster recovery
![Page 12: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/12.jpg)
LAW REQUIREMENTSIn Italy, the “Codice dell’Amministrazione Digitale” defines business continuity requirements for public
administrations
![Page 13: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/13.jpg)
WARNING FOR THE SUPERSTITIOUS
You are now allowed to touch wood
![Page 14: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/14.jpg)
DISASTER(too late for touching wood now)
system/hardware failuresunintentional errors
natural disaster
![Page 15: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/15.jpg)
REACT TO A DISASTERRecover systems, data and infrastructures
![Page 16: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/16.jpg)
TOO LATE!Do not wait for a disaster to happen
![Page 17: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/17.jpg)
PLAN FOR DISASTERS“Disasters” will happen. Be prepared.
![Page 18: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/18.jpg)
“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 19: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/19.jpg)
REGULAR CRASH TESTS
![Page 20: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/20.jpg)
DATABASEDISASTER RECOVERY
Let’s just focus on databases!
![Page 21: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/21.jpg)
REQUIREMENTS
• Automated backups
• Notifications (anomalies)
• Frequency of backups
• Retention policies
• Data protection
• Availability for recovery
![Page 22: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/22.jpg)
TYPES OF BACKUP
• Full backup
• Incremental backup
• Differential backup
• Hot backup
• Logical backup
• Physical backup
![Page 23: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/23.jpg)
POSTGRES BACKUP
• Hot backup
•MVCC (core)
• Logical Backup
• pg_dump
• Physical Backup
• Full backup (base backup)
•Differential backup (WAL)
• Incremental backup
•N/A
![Page 24: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/24.jpg)
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 25: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/25.jpg)
EXISTING TOOLS
•Omni-PITR
•WAL centric
•WALmgr
•WAL centric
• pg-rman
• Server centric
•WAL-E
• EC2 centric, but ...
• good
• came later
![Page 26: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/26.jpg)
NONE FOR DRNone of them was a pure disaster recovery solution.
We wanted something similar to Oracle’s RMAN.
![Page 27: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/27.jpg)
FILLING A HOLEThe lack of a DR solution is a barrier towards the adoption
of PostgreSQL from Oracle users’ point of view.
![Page 28: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/28.jpg)
OUR GOALS
• 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 30: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/30.jpg)
PART IIDisaster recovery with Barman for PostgreSQL
![Page 31: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/31.jpg)
BARMAN
• GNU GPL 3
• Hosted on Sourceforge.net
• Linux
• Python 2.6/2.7 (3.0 exp.)
• PostgreSQL 8.4 to 9.3
• PyPI package
• RPM package
•Debian/Ubuntu package
•Designed, developed, maintained by 2ndQuadrant
![Page 32: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/32.jpg)
Postgres Postgres Postgres
Barman
LAN, centralised architecture
Barman
LAN, hybrid architecture
tape
![Page 33: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/33.jpg)
Postgres
Barman
Geographic redundancy
Barman
data centre 1 data centre 2
rsync
![Page 34: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/34.jpg)
Postgres
Barman
Continuous archiving(WAL shipping via SSH)
SSH commandsSQL commands
![Page 35: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/35.jpg)
secure channel
Postgres Barman
WAL cron
Barman’sWAL archive
![Page 36: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/36.jpg)
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 37: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/37.jpg)
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 38: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/38.jpg)
CONFIGURATION FILE
[barman]barman_home = /srv/barmanbarman_user = barmanlog_file = /var/log/barman/barman.loglog_level = NOTICEcompression = gzip
[production]description = Production PostgreSQLssh_command = ssh [email protected] = host=pg.2ndQuadrant.it user=postgrescompression = bzip2
![Page 39: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/39.jpg)
MULTI-SERVER CONFIGURATION
[barman]; General configuration; …[server_one]; Configuration for Server 1; …[server_two]; Configuration for Server 2; …[server_X]; …
![Page 40: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/40.jpg)
MULTIPLE FILES INCLUSION
[barman]; General configuration; …configuration_files_directory = /etc/barman.d
![Page 41: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/41.jpg)
CONVENTION OVER CONFIGURATION
global/per server optionsdefault directory layout
![Page 42: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/42.jpg)
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 43: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/43.jpg)
GLOBAL COMMANDS
• List of managed servers
• barman list-server
• Maintenance operations
• barman cron
![Page 44: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/44.jpg)
SERVER COMMANDS
• Information and diagnostics
• barman status
• barman check
• barman show-server
• barman list-backup
• Backup control
• Recovery control
![Page 45: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/45.jpg)
![Page 46: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/46.jpg)
BACKUP CONTROL
• barman backup
• barman show-backup
• barman list-files
• standalone, data, wal, full
• barman delete
![Page 47: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/47.jpg)
![Page 48: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/48.jpg)
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 49: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/49.jpg)
![Page 50: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/50.jpg)
RECOVERY CONTROL
• Recovery target (full / point in time)
• Local recovery
• barman recover
• Remote recovery
• barman recover --remote-ssh-command
![Page 51: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/51.jpg)
ADVANCED RECOVERY
• Point In Time Recovery
• --target-time = TIME
• --target-xid = XID
• --target-name = NAME (for 9.1+)
• Relocation of tablespaces
• --tablespace NAME:LOCATION [...]
![Page 52: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/52.jpg)
COMMON USE CASES
• Unintentional errors recovery
•Disaster recovery
• Sandbox server (BI, staging, ...)
![Page 53: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/53.jpg)
![Page 54: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/54.jpg)
RETENTION POLICIES
• User-defined policy
• How long backups are retained for recovery
• Point of recoverability
• REDUNDANCY
• RECOVERY WINDOW
![Page 55: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/55.jpg)
RETENTION POLICY CONFIGURATION
; Base backup retention policyretention_policy = 'redundancy 3'retention_policy = 'recovery window of 3 months'
![Page 56: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/56.jpg)
BANDWIDTH CONTROL
• You can limit I/O bandwidth usage
• bandwidth_limit global/server option
• tablespace_bandwidth_limit on a per tablespace basis
• Unit of measure: kilobytes (default 0, no limits)
![Page 57: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/57.jpg)
BANDWIDTH LIMIT CONFIGURATION
[barman]bandwidth_limit = 4096
[server_one];...bandwidth_limit = 1024
[server_two];...tablespace_bandwidth_limit = tbs01:4096,tbs02:2048
![Page 58: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/58.jpg)
BACKLOG
• Incremental backup
• Better recovery support
• Sandbox recovery
• Logical backup integration
• pg_dump on sandbox instances
• Backup from standby
• More hook scripts
• TAR format for backups
• Export/Import of backups
• External backups
• SSH only connections
• Replication protocol support
• libpq only connections
• pg_basebackup
• WAL streaming (0 Data Loss)
• Backup server
• Windows support
• JSON output for full automation
• Backup validation
• ...
![Page 59: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/59.jpg)
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 60: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/60.jpg)
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 61: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/61.jpg)
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 62: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/62.jpg)
TIME TO ...yum install barman
apt-get install barman
![Page 64: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/64.jpg)
THANK YOU!
![Page 65: PostgreSQL Disaster Recovery with Barman (PGConf.EU 2013)](https://reader033.vdocuments.site/reader033/viewer/2022060123/559708211a28ab932f8b467c/html5/thumbnails/65.jpg)
LICENSE
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
Copyright (c) 2012, 2013 - 2ndQuadrant.it