os: ubuntu 16.04
postgresql: 9.6.8
barman: 2.5
ip 规划
192.168.56.101 node1 barman
192.168.56.102 node2 postgresql
barman 是2ndquadrant推出的一款 postgresql 开源备份软件,官网介绍的非常强大。
barman 建议以一个 dedicated server 存在。尽量不要部署到 postgresql server 上,但不是不能部署到 postgresql server 主机上。
node1 修改配置文件
/etc/barman.d/dn1-ssh.conf
# egrep ^[^";"] /etc/barman.d/dn1-ssh.conf
[dn1_ssh]
description = "dn1 PostgreSQL Database (via SSH)"
ssh_command = ssh postgres@192.168.56.102
conninfo = host=192.168.56.102 user=barman dbname=postgres
backup_method = rsync
reuse_backup = copy
parallel_jobs = 1
archiver = on
node1、node2 配置相互免密登录
过程略,可参考另外一篇blog。
https://blog.csdn.net/ctypyb2002/article/details/80572181
需要注意的是 node1 在 barman 用户下,node2 在 postgres 用户下。
node1 查看
barman@nodex:~$ barman show-server dn1_ssh |grep incoming_wals_directory
incoming_wals_directory: /var/lib/barman/dn1_ssh/incoming
node2 修改 postgresql.conf
postgres@nodex:~$ vi /etc/postgresql/9.6/main/postgresql.conf
archive_command = 'gzip < %p > /data/backup/pgwalarchive/%f.gz && rsync -a %p barman@192.168.56.101:/var/lib/barman/dn1_ssh/incoming/%f'
node1 查看定义的 server_name
barman@nodex:~$ barman show-server all
barman@nodex:~$ barman check dn1_ssh
Server dn1_ssh:
PostgreSQL: OK
is_superuser: 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 0 backups, expected at least 0)
ssh: OK (PostgreSQL server)
not in recovery: OK
archive_mode: OK
archive_command: OK
continuous archiving: OK
archiver errors: OK
barman@nodex:~$ barman backup dn1_ssh
Starting backup using rsync-exclusive method for server dn1_ssh in /var/lib/barman/dn1_ssh/base/20181008T155150
Backup start at LSN: 0/17000028 (000000010000000000000017, 00000028)
This is the first backup for server dn1_ssh
WAL segments preceding the current backup have been found:
000000010000000000000015 from server dn1_ssh has been removed
Starting backup copy via rsync/SSH for 20181008T155150
Copy done (time: 2 seconds)
This is the first backup for server dn1_ssh
Asking PostgreSQL server to finalize the backup.
Backup size: 21.1 MiB
Backup end at LSN: 0/17000130 (000000010000000000000017, 00000130)
Backup completed (start time: 2018-10-08 15:51:52.151974, elapsed time: 3 seconds)
barman@nodex:~$ barman status dn1_ssh
Server dn1_ssh:
Description: dn1 PostgreSQL Database (via SSH)
Active: True
Disabled: False
PostgreSQL version: 9.6.8
Cluster state: in production
pgespresso extension: Not available
Current data size: 21.0 MiB
PostgreSQL Data directory: /data/pg9.6/main
Current WAL segment: 000000010000000000000018
PostgreSQL 'archive_command' setting: gzip < %p > /data/backup/pgwalarchive/%f.gz && rsync -a %p barman@192.168.56.101:/var/lib/barman/dn1_ssh/incoming/%f
Last archived WAL: 000000010000000000000017.00000028.backup, at Mon Oct 8 15:51:56 2018
Failures of WAL archiver: 17 (000000010000000000000015 at Mon Oct 8 15:32:55 2018)
Server WAL archiving rate: 2.22/hour
Retention policies: not enforced
No. of available backups: 1
First available backup: 20181008T155150
Last available backup: 20181008T155150
Minimum redundancy requirements: satisfied (1/0)
参考:
https://www.2ndquadrant.com/en/resources/barman/
https://sourceforge.net/projects/pgbarman/files/
https://sourceforge.net/projects/pgbarman/files/2.4/
https://www.pgbarman.org/about/
https://www.pgbarman.org/documentation/
http://docs.pgbarman.org/release/2.4/