2ndQuadrant is now part of EDB

Bringing together some of the world's top PostgreSQL experts.

2ndQuadrant | PostgreSQL
Mission Critical Databases
  • Contact us
  • EN
    • FR
    • IT
    • ES
    • DE
    • PT
  • Support & Services
  • Products
  • Downloads
    • Installers
      • Postgres Installer
      • 2UDA – Unified Data Analytics
    • Whitepapers
      • Business Case for PostgreSQL Support
      • Security Best Practices for PostgreSQL
    • Case Studies
      • Performance Tuning
        • BenchPrep
        • tastyworks
      • Distributed Clusters
        • ClickUp
        • European Space Agency (ESA)
        • Telefónica del Sur
        • Animal Logic
      • Database Administration
        • Agilis Systems
      • Professional Training
        • Met Office
        • London & Partners
      • Database Upgrades
        • Alfred Wegener Institute (AWI)
      • Database Migration
        • International Game Technology (IGT)
        • Healthcare Software Solutions (HSS)
        • Navionics
  • Postgres Learning Center
    • Webinars
      • Upcoming Webinars
      • Webinar Library
    • Whitepapers
      • Business Case for PostgreSQL Support
      • Security Best Practices for PostgreSQL
    • Blog
    • Training
      • Course Catalogue
    • Case Studies
      • Performance Tuning
        • BenchPrep
        • tastyworks
      • Distributed Clusters
        • ClickUp
        • European Space Agency (ESA)
        • Telefónica del Sur
        • Animal Logic
      • Database Administration
        • Agilis Systems
      • Professional Training
        • Met Office
        • London & Partners
      • Database Upgrades
        • Alfred Wegener Institute (AWI)
      • Database Migration
        • International Game Technology (IGT)
        • Healthcare Software Solutions (HSS)
        • Navionics
    • Books
      • PostgreSQL 11 Administration Cookbook
      • PostgreSQL 10 Administration Cookbook
      • PostgreSQL High Availability Cookbook – 2nd Edition
      • PostgreSQL 9 Administration Cookbook – 3rd Edition
      • PostgreSQL Server Programming Cookbook – 2nd Edition
      • PostgreSQL 9 Cookbook – Chinese Edition
    • Videos
    • Events
    • PostgreSQL
      • PostgreSQL – History
      • Who uses PostgreSQL?
      • PostgreSQL FAQ
      • PostgreSQL vs MySQL
      • The Business Case for PostgreSQL
      • Security Information
      • Documentation
  • About Us
    • About 2ndQuadrant
    • 2ndQuadrant’s Passion for PostgreSQL
    • News
    • Careers
    • Team Profile
  • Blog
  • Menu Menu
You are here: Home1 / Blog2 / Barman3 / Automating Barman with Puppet: it2ndq/barman (part one)
Francesco Canovai

Automating Barman with Puppet: it2ndq/barman (part one)

March 17, 2015/1 Comment/in Barman, Francesco's PlanetPostgreSQL, PostgreSQL /by Francesco Canovai

vagrant-barman-vertical
This is not the first time that 2ndQuadrant has looked at Puppet. Gabriele Bartolini has already written an article in two parts on how to rapidly configure a PostgreSQL server through Puppet and Vagrant, accompanied by the release of the code used in the example on GitHub (http://github.com/2ndquadrant-it/vagrant-puppet-postgresql).

Split into three parts, the aim of this article is to demonstrate automation of the setup and configuration of Barman to backup a PostgreSQL test server.

This article is an update of what was written by Gabriele with the idea of creating two virtual machines instead of one, a PostgreSQL server and a Barman server.

it2ndq/barman is the module released by 2ndQuadrant Italy to manage the installation of Barman through Puppet. The module has a GPLv3 licence and is available on GitHub at the address http://github.com/2ndquadrant-it/puppet-barman. The following procedure was written for an Ubuntu 14.04 Trusty Tahr but can be performed in a similar manner on other distributions.

Requirements

To start the module for Barman on a virtual machine, we need the following software:

  • VirtualBox
  • Vagrant
  • Ruby >= 1.9
  • Puppet
  • librarian-puppet

Vagrant

Vagrant is a virtual machine manager, capable of supporting many virtualisation softwares with VirtualBox as its default.

We install VirtualBox this way:

$ sudo apt-get install virtualbox virtualbox-dkms

The latest version of Vagrant can be downloaded from the site and installed with the command:

$ sudo dpkg -i /path/to/vagrant_1.7.2_x86_64.deb

Ruby

Regarding Ruby, our advice is to use rbenv, which creates a Ruby development environment in which to specify the version for the current user, thereby avoiding contaminating the system environment. To install rbenv we suggest to use rbenv-installer (http://github.com/fesplugas/rbenv-installer).

Let’s download and execute the script:

$ curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash

At the end, the script will prompt you to append the following lines to the ~/.bash_profile file:

export RBENV_ROOT="${HOME}/.rbenv"

if [ -d "${RBENV_ROOT}" ]; then
  export PATH="${RBENV_ROOT}/bin:${PATH}"
  eval "$(rbenv init -)"
fi

We now need to reload the just changed ~/.bash_profile:

$ exec bash -l

At this point, we locally install a Ruby version (in this case, 2.1.5) and set the user to run this version rather than the system version:

$ rbenv install 2.1.5
$ rbenv global 2.1.5

Puppet

Puppet is required not only on the VMs but also on the machine running them. Therefore we need to install the Puppet gem.

$ gem install puppet

Librarian-puppet

Finally, librarian-puppet is a tool to automate the Puppet modules management. Like Puppet, librarian-puppet can be installed as a gem:

$ gem install librarian-puppet

Vagrant: configuration

Now that we have the dependencies in place, we can start to write the Vagrant and Puppet configurations for our backup system.

We start by creating a working directory:

$ mkdir ~/vagrant_puppet_barman
$ cd ~/vagrant_puppet_barman

Vagrant needs us to write a file called Vagrantfile where it looks for the configuration of the VMs.

The following Vagrantfile starts two Ubuntu Trusty VMs, called pg and backup, with ip addresses 192.168.56.221 and 192.168.56.222. On both machines provisioning will be performed through an inline shell script.

This script launches puppet-bootstrap (http://github.com/hashicorp/puppet-bootstrap), a script that automatically installs and configures Puppet on various types of machines. As it does not need to be run more than once, in the script a test was inserted to prevent further executions.

Vagrant.configure("2") do |config|
  {
    :pg => {
      :ip      => '192.168.56.221',
      :box     => 'ubuntu/trusty64'
    },
    :backup => {
      :ip      => '192.168.56.222',
      :box     => 'ubuntu/trusty64'
    }
  }.each do |name,cfg|
    config.vm.define name do |local|
      local.vm.box = cfg[:box]
      local.vm.hostname = name.to_s + '.local.lan'
      local.vm.network :private_network, ip: cfg[:ip]
      family = 'ubuntu'
      bootstrap_url = 'http://raw.github.com/hashicorp/puppet-bootstrap/master/' + family + '.sh'

      # Run puppet-bootstrap only once
      local.vm.provision :shell, :inline => <<-eos
        if [ ! -e /tmp/.bash.provision.done ]; then
          curl -L #{bootstrap_url} | bash
          touch /tmp/.bash.provision.done
        fi
      eos
    end
  end
end

Bringing up the VMs

We have defined two Ubuntu Trusty VMs containing Puppet. This is not the final Vagrantfile but already allows the creation of the two machines. If you’re curious, it is possible to verify that the two machines have been created with the command:

$ vagrant up

and then connecting using the following commands:

$ vagrant ssh pg
$ vagrant ssh backup

Finally, the machines can be destroyed with:

$ vagrant destroy -f

Conclusions

In this first part of the tutorial we’ve seen how to configure the dependencies and ended up with the two virtual machines on which we’ll install, via Puppet, PostgreSQL and Barman. Writing the Puppet manifest for the actual installation will be the subject of the next article.

Bye for now!

Tags: automation, backup, Barman, it2ndq/barman, postgres, PostgreSQL, puppet, vagrant
Share this entry
  • Share on Facebook
  • Share on Twitter
  • Share on WhatsApp
  • Share on LinkedIn
1 reply

Trackbacks & Pingbacks

  1. Automating Barman with Puppet: it2ndq/barman (part two) | 2ndQuadrant says:
    April 1, 2015 at 9:49 am

    […] the first part of this article we configured Vagrant to execute two Ubuntu 14.04 Trusty Tahr virtual machines, respectively called […]

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Get in touch with us!

Recent Posts

  • Random Data December 3, 2020
  • Webinar: COMMIT Without Fear – The Beauty of CAMO [Follow Up] November 13, 2020
  • Full-text search since PostgreSQL 8.3 November 5, 2020
  • Random numbers November 3, 2020
  • Webinar: Best Practices for Bulk Data Loading in PostgreSQL [Follow Up] November 2, 2020

Featured External Blogs

Tomas Vondra's Blog

Our Bloggers

  • Simon Riggs
  • Alvaro Herrera
  • Andrew Dunstan
  • Craig Ringer
  • Francesco Canovai
  • Gabriele Bartolini
  • Giulio Calacoci
  • Ian Barwick
  • Marco Nenciarini
  • Mark Wong
  • Pavan Deolasee
  • Petr Jelinek
  • Shaun Thomas
  • Tomas Vondra
  • Umair Shahid

PostgreSQL Cloud

2QLovesPG 2UDA 9.6 backup Barman BDR Business Continuity community conference database DBA development devops disaster recovery greenplum Hot Standby JSON JSONB logical replication monitoring OmniDB open source Orange performance PG12 pgbarman pglogical PG Phriday postgres Postgres-BDR postgres-xl PostgreSQL PostgreSQL 9.6 PostgreSQL10 PostgreSQL11 PostgreSQL 11 PostgreSQL 11 New Features postgresql repmgr Recovery replication security sql wal webinar webinars

Support & Services

24/7 Production Support

Developer Support

Remote DBA for PostgreSQL

PostgreSQL Database Monitoring

PostgreSQL Health Check

PostgreSQL Performance Tuning

Database Security Audit

Upgrade PostgreSQL

PostgreSQL Migration Assessment

Migrate from Oracle to PostgreSQL

Products

HA Postgres Clusters

Postgres-BDR®

2ndQPostgres

pglogical

repmgr

Barman

Postgres Cloud Manager

SQL Firewall

Postgres-XL

OmniDB

Postgres Installer

2UDA

Postgres Learning Center

Introducing Postgres

Blog

Webinars

Books

Videos

Training

Case Studies

Events

About Us

About 2ndQuadrant

What does 2ndQuadrant Mean?

News

Careers 

Team Profile

© 2ndQuadrant Ltd. All rights reserved. | Privacy Policy
  • Twitter
  • LinkedIn
  • Facebook
  • Youtube
  • Mail
What’s new about Barman 1.4.0? Dynamic SQL-level configuration for BDR 0.9.0
Scroll to top
×