Tuesday 31 October 2017

PostgreSQL | BARMAN (Backup and recovery Manager)

Here again i am trying to explore another backup and recovery tool for PostgreSQL that is BARMAN Earlier i have tried PgBackRest

So ,Lets start with the BARMAN .

Below is features of BARMAN .
  • Full hot physical backup of a PostgreSQL server
  • Point-In-Time-Recovery (PITR)
  • Management of multiple PostgreSQL servers
  • Remote backup of a PostgreSQL server
  • Remote recovery of a backup for a PostgreSQL server
  • Management of base backups and WAL files through a catalog
  • ssh support for remote operations
  • rsync over ssh support for file synchronisation and transfers
  • Management of retention policies for backups and WAL files
  • Incremental backup
  • WAL hub (get-wal)
  • Compression of WAL files (bzip2, gzip or custom)
  • Backup general and disk usage information
  • Integration with standard archiving tools (e.g. tar)
  • Local recovery
  • Relocation of PGDATA and tablespaces at recovery time
  • Server diagnostics for backup
  • Server status and information
  • Pre/Post backup hook scripts
  • Local storage of metadata
  • INI configuration file
  • Written in Python
  • Control of bandwidth usage
Below are packages should be with you . 

  • 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)
Note : Password less (SSH) login should be in place between DB server and BARMAN server .

Below are steps to install python and related packages . 


yum install -y centos-release-SCL
yum install -y python27
yum install python-six
yum install python-argparse
yum install python-argcomplete
yum install python-argh

curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py


https://pypi.python.org/pypi/python-dateutil/2.6.1
tar -xvf python-dateutil-2.6.1.tar.gz
python setup.py build
python setup.py install


pip install -U pip
pip install psycopg2

pip install argh
pip install argcomplete

Below are the steps to install BARMAN


https://sourceforge.net/projects/pgbarman/?source=typ_redirect
tar -xvf barman-2.3.tar.gz
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/PostgreSQL9.6S/lib
export PATH=/opt/PostgreSQL9.6S/bin/:$PATH
python setup.py build
python setup.py install

useradd -m -d /home/barman/ barman

chown barman:root /etc/barman

mkdir -p /etc/barman

cp /barman-2.3/doc/barman.conf /etc/barman



Parameters need to adjust in barman.conf
Global section of in barman.conf ,Global section name is [barman]

[barman]
barman_home = /var/lib/barman   - Backup and wal path
barman_user = barman
log_file = /var/log/barman/barman.log - Log file
compression = gzip
minimum_redundancy = 1
immediate_checkpoint = true

DB- server section from barman.conf 
pg-remote is server name i have given .

[pg-remote]
description =  "PostgreSQL Server"
ssh_command = ssh postgres@192.168.213.141
conninfo = host=192.168.213.141 user=postgres  port=5411
archiver=on
streaming_archiver = off
reuse_backup = link

Parameters need to adjust in postgresql.conf and pg_hba.conf on DB server .



postgresql.conf entries 

listen_addresses = *
max_wal_senders = 3
archive_mode = on
wal_level=logical/replica/archive
archive_command =  rsync -a %p barman@192.168.213.236:/var/lib/barman/pg-remote/incoming/%f

To get location of wal_dir on barman server ,Execute below command 
//barman show-server pg-remote |grep incoming_wals_directory 
//incoming_wals_directory: /var/lib/barman/pg-remote/incoming/

pg_hba.conf entries 

Allow replication user connection from that server .

host     all     all               192.168.213.236/32      trust
host     replication     postgres               192.168.213.236/32      trust

Execute below command 

/usr/bin/barman archive-wal pg-remote

Where pg-remote is server name .

Below image shows some of the ,Examples .

/usr/bin/barman archive-wal pg-remote
/usr/bin/barman check pg-remote
/usr/bin/barman list-server
/usr/bin/barman status pg-remote
/usr/bin/barman show-server pg-remote 


































Now we will take a backup for one server . 

/usr/bin/barman backup pg-remote


List out the backups ,By using below commands .





Now,Lets restore some backup of remote host .