Project

rbarman

0.01
No commit activity in last 3 years
No release in over 3 years
Wrapper for 2ndQuadrant's PostgreSQL backup tool 'barman'
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 2.14.0

Runtime

 Project Readme

rbarman

Build Status

rbarman - Ruby Wrapper for 2ndQuadrant's PostgreSQL backup tool barman

Installation

barman has to be installed and configured on the same host where this gem is to be used, otherwise it cannot get any useful information about your backups ;)

Add this line to your application's Gemfile:

gem 'rbarman'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rbarman

Usage

Just a few examples. Please read the documentation for more details.

Get all your backups!

This will call various barman commands and some other sources (backup.info, xlog.db) to get information about your backups and could take several minutes (and memory) if you have many backups with thousand of wal files.

servers = RBarman::Servers.all({:with_backups => true, :with_wal_files => true })
servers.count
=> 3

servers[0].name
=> "pgmaster"

servers[0].ssh_cmd
=> "ssh postgres@10.118.19.4"

servers[0].backups.count
=> 2

servers[0].backups.each { |b| p "id: #{b.id} }
=> "id: 20130304T080002"
=> "id: 20130225T192654"
=> "id: 20130218T080002"

backups = servers[0].backups
backups.latest.id
=> "20130304T080002"

backups.oldest.id
=> "20130218T080002"

backups[0].status
=> :done    # :started, :failed, :empty

backups[0].backup_start.to_s
=> "2013-03-04 08:00:02 +0100"

backups[0].backup_end.to_s
=> "2013-03-04 16:46:28 +0100"

backups[0].size
=> 201071500850 # bytes

backups[0].wal_file_size
=> 41875931136  # bytes

backups[0].timeline
=> 1

backups[0].begin_wal.xlog
=> "0000058F"

backups[0].end_wal.segment
=> "000000A5"

backups[0].wal_files.count
=> 9019

backups[0].wal_files[1022].compression
=> :bzip2

Get just one backup without wal files

backup = RBarman::Backup.by_id('pg_master', '20130225T192654')
p "id: #{backup.id}|size: #{backup.size / (1024 ** 3) } GB|wal size: #{backup.wal_file_size / (1024 ** 3)} GB"
=> "id: 20130225T192654|size: 217GB|wal size: 72 GB"

Create a backup

Creates a new backup (and probably takes some time)

b = RBarman::Backup.create('server')
p b.id
=> "20130304T131422"

Delete a backup

This instructs barman to delete the specified backup

backup = RBarman::Backup.by_id('server', '20130225T192654', { :with_wal_files => false })
p backup.deleted
=> false
backup.delete
p backup.deleted
=> true

Recover a backup

Recovers newest/latest backup to the specified path on the remote host

RBarman::Backups.all('testdb').latest.recover('/var/lib/postgresql/9.2/main', 
    { :remote_ssh_cmd => 'ssh postgres@10.20.20.2' })

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Meta

Written by Holger Amann, sponsored by Sauspiel GmbH

Release under the MIT License