2. Database backups
A. SQL Dump
– .sql or custom format for pg_dump/pg_restore
– high CPU and disk demands
B. File system level backup
– offline database server or LVM / file system snapshot
C. Continuous Archiving and Point-in-Time Recovery
3. Point-in-Time Recovery
– Utilizes write ahead log (WAL)
– Pros
– ability to restore to a specific timestamp or transaction ID
– minimum CPU overhead
– Cons
– disk space requirements
– possibly long restore time
– several caveats
4. Common use cases
– Unintentional errors recovery
– Disaster recovery
– Sandbox server (BI, staging)
http://www.slideshare.net/openobject/odoo-disaster-recovery-with-barman
5. – Incremental backups (hard links)
– WAL compression
– Easy installation and config
– pip install barman
postgresql.conf:
wal_level = 'archive' # For PostgreSQL >= 9.0
archive_mode = on
archive_command = 'rsync -a %p barman@backup:WALS_DIRECTORY/%f'
6. Periodical and differential
backups
– Full backup (weekly / monthly)
– reduces time needed for recovery
# m h dom mon dow command
0 8 * * 1 barman backup SERVER_ID
– Differential backup (WAL files)
– continuos archiving (rsync / ssh)
8. Disaster recovery
– Recover to specified time
$ barman recover main 20150715T230232 /path/to/recover/directory --target-time
"2015-07-16 9:00:00 CEST”
– Run standalone Postgres server
$ pg_ctl -D /path/to/recover/directory start
2015-09-15 23:17:57 CEST LOG: database system was interrupted; last known up at 2015-09-14 08:05:06 CEST
2015-09-15 23:20:18 CEST LOG: redo starts at 52/5333C080
2015-09-15 23:20:19 CEST LOG: consistent recovery state reached at 52/543A28E8
2015-09-15 23:20:19 CEST LOG: consistent recovery state reached at 52/543A28E8
2015-09-15 23:21:11 CEST LOG: redo done at 53/1FFFE2E0
2015-09-15 23:21:11 CEST LOG: last completed transaction was at log time 2015-09-15 23:18:02.661924+02
2015-09-15 23:22:30 CEST LOG: MultiXact member wraparound protections are now enabled
2015-09-15 23:22:30 CEST LOG: database system is ready to accept connections
2015-09-15 23:22:30 CEST LOG: autovacuum launcher started