postgresql 物理备份 barman 之 安装

訾凯歌
2023-12-01

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 节点上安装 barman

# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.3 LTS
Release:	16.04
Codename:	xenial

官方文档 http://docs.pgbarman.org/release/2.4/#system-requirements 提示说barman 有一些依赖包需要安装。

Linux/Unix
Python 2.6 or 2.7
Python modules:
	argcomplete
	argh >= 0.21.2 <= 0.26.2
	argparse (Python 2.6 only)
	psycopg2 >= 2.4.2
	python-dateutil <> 2.0
	setuptools
PostgreSQL >= 8.3
rsync >= 3.0.4 (optional for PostgreSQL >= 9.2)

还是配置个 2ndQuadrant Public APT repository
https://dl.2ndquadrant.com/default/release/site/

# curl https://dl.2ndquadrant.com/default/release/get/deb | bash
# 
# ls -l /etc/apt/sources.list.d/
total 4
-rw-r--r-- 1 root root 88 Sep 30 08:25 2ndquadrant-dl-default-release.list

安装barman

# apt-get install barman barman-cli
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-argcomplete python-argh
  python-dateutil python-egenix-mxdatetime python-egenix-mxtools python-minimal python-psycopg2
  python-six python2.7 python2.7-minimal
Suggested packages:
  repmgr python-doc python-tk python-egenix-mxdatetime-dbg python-egenix-mxdatetime-doc
  python-egenix-mxtools-dbg python-egenix-mxtools-doc python-psycopg2-doc python2.7-doc binutils
  binfmt-support
The following NEW packages will be installed:
  barman libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-argcomplete
  python-argh python-dateutil python-egenix-mxdatetime python-egenix-mxtools python-minimal
  python-psycopg2 python-six python2.7 python2.7-minimal
0 upgraded, 15 newly installed, 0 to remove and 171 not upgraded.
Need to get 4,381 kB of archives.
After this operation, 19.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

需要安装的包还真不少。所以说尽量用 yum 或者 apt 安装这些软件,有时候依赖包搞得你很烦心。

# dpkg -l |grep -i barman
ii  barman                              2.4-1.xenial+1                             all          Backup and Recovery Manager for PostgreSQL
ii  barman-cli                          1.2-1.xenial+1                             all          Client utilities for the integration of Barman in PostgreSQL clusters

安装了 barman barman-cli

# cat /etc/passwd |grep -i barman
barman:x:112:119:Backup and Recovery Manager for PostgreSQL,,,:/var/lib/barman:/bin/bash

还创建了个os用户。

# which barman
barman              barman-wal-restore
# which barman
/usr/bin/barman
# which barman-wal-restore 
/usr/bin/barman-wal-restore

两个命令

/etc
/etc/barman.conf
/etc/barman.d
/etc/barman.d/streaming-server.conf-template
/etc/barman.d/ssh-server.conf-template
/etc/cron.d
/etc/cron.d/barman
/etc/logrotate.d
/etc/logrotate.d/barman

一些配置文件

其中 /etc/logrotate.d/barman 是定义了 barman log 的保留策略。

# cat /etc/logrotate.d/barman 
/var/log/barman/barman.log {
    weekly
    rotate 4
    delaycompress
    compress
    missingok
    notifempty
    create 0640 barman adm
}

备份配置

barman 有两种备份形式:streaming,ssh/rsync

node1 上修改一个公共配置文件
/etc/barman.conf

# egrep ^[^";"] /etc/barman.conf 
[barman]
barman_user = barman
configuration_files_directory = /etc/barman.d
barman_home = /var/lib/barman
log_file = /var/log/barman/barman.log
log_level = INFO
compression = gzip

可以认为 /etc/barman.d/ 下面的每一个 .conf 代表一个配置,通过文件内容开头的 [] 来定义 server_name。

最好文件名有个含义,让人一看就知道是做什么用的。

node2 上创建两个barman相关联用户

# su - postgres 
# createuser -s -P barman
# createuser -P --replication streaming_barman

之后配置好 pg_hba.conf。这里不再啰嗦。

node1 上创建 .gpass

barman@nodex:~$ vi ~/.pgpass
192.168.56.102:5432:*:streaming_barman:rootroot
192.168.56.102:5432:*:barman:rootroot

至此,barman 在 ubuntu 16.04 上安装完成。

参考:
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/

https://github.com/2ndquadrant-it/barman

 类似资料: