Coder Social home page Coder Social logo

rbarman's Introduction

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 [email protected]"

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 [email protected]' })

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

rbarman's People

Contributors

hamann avatar jordiromera avatar mk avatar

Stargazers

 avatar Alexander Dobriakov avatar  avatar Henry Yan avatar Elikem Adadevoh avatar  avatar Anthony Scalisi avatar Alexey Tsverov avatar Ernad Husremović avatar

Watchers

Leah Neukirchen avatar Dieter Komendera avatar  avatar Mathias Meyer avatar  avatar James Cloos avatar Anthony Scalisi avatar

rbarman's Issues

RBarman::InvalidWalFileNameError for "00000002.history"

Hi,

The following command:

sudo -u barman /usr/bin/ruby /var/lib/barman/prog/check_barman/check-barman.rb -a last_wal_received -s db -w 1 -c 2

raises this following error:

/var/lib/gems/2.1.0/gems/rbarman-0.0.16/lib/rbarman/wal_file.rb:109:in `parse': name '00000002.history' has to be exactly 24 chars (RBarman::InvalidWalFileNameError)
	from /var/lib/gems/2.1.0/gems/rbarman-0.0.16/lib/rbarman/cli_command.rb:195:in `block in parse_wal_files_list'
	from /var/lib/gems/2.1.0/gems/rbarman-0.0.16/lib/rbarman/cli_command.rb:194:in `each'
	from /var/lib/gems/2.1.0/gems/rbarman-0.0.16/lib/rbarman/cli_command.rb:194:in `parse_wal_files_list'
	from /var/lib/gems/2.1.0/gems/rbarman-0.0.16/lib/rbarman/cli_command.rb:119:in `wal_files'
	from /var/lib/gems/2.1.0/gems/rbarman-0.0.16/lib/rbarman/cli_command.rb:71:in `block in backups'
	from /var/lib/gems/2.1.0/gems/rbarman-0.0.16/lib/rbarman/cli_command.rb:68:in `each'
	from /var/lib/gems/2.1.0/gems/rbarman-0.0.16/lib/rbarman/cli_command.rb:68:in `backups'
	from /var/lib/gems/2.1.0/gems/rbarman-0.0.16/lib/rbarman/cli_command.rb:54:in `backup'
	from /var/lib/gems/2.1.0/gems/rbarman-0.0.16/lib/rbarman/backup.rb:298:in `by_id'
	from /var/lib/barman/prog/check_barman/check-barman.rb:84:in `check_last_wal_received'
	from /var/lib/barman/prog/check_barman/check-barman.rb:243:in `<main>'

This is following a PITR recovery of the DB, I suspect this 00000002.history is perfectly valid

barman@barman2:~$ barman -v
2.3

Barman by 2ndQuadrant (www.2ndQuadrant.com)
barman@barman2:~$ barman list-files --target wal db 20230319T042101 | head
/var/lib/barman/db/wals/00000002.history
/var/lib/barman/db/wals/0000000200002E80/0000000200002E8000000075
/var/lib/barman/db/wals/0000000200002E80/0000000200002E8000000076
/var/lib/barman/db/wals/0000000200002E80/0000000200002E8000000077
/var/lib/barman/db/wals/0000000200002E80/0000000200002E8000000078
/var/lib/barman/db/wals/0000000200002E80/0000000200002E8000000079

I'm not sure on what to do to fix this...

A failed backup results in parse errors

Hi,

Exception is:

/usr/local/rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/time.rb:267:in `parse': no time information in "None" (ArgumentError)
    from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/rbarman-0.0.13/lib/rbarman/backup.rb:116:in `backup_start='
    from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/rbarman-0.0.13/lib/rbarman/cli_command.rb:239:in `block in parse_backup_info_file'
    from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/rbarman-0.0.13/lib/rbarman/cli_command.rb:235:in `each'
    from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/rbarman-0.0.13/lib/rbarman/cli_command.rb:235:in `parse_backup_info_file'
    from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/rbarman-0.0.13/lib/rbarman/cli_command.rb:69:in `block in backups'
    from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/rbarman-0.0.13/lib/rbarman/cli_command.rb:68:in `each'
    from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/rbarman-0.0.13/lib/rbarman/cli_command.rb:68:in `backups'
    from /usr/local/rvm/gems/ruby-1.9.3-p545/gems/rbarman-0.0.13/lib/rbarman/backups.rb:20:in `all'
    from ./check-barman.rb:78:in `check_last_wal_received'
    from ./check-barman.rb:202:in `<main>'

Problem is that a failed backup has no begin time, end time, as I'm not fluid in ruby I can't look for the exact code portion, I think you will be faster with that!

Here is the output from show-backup:

Backup 20140518T220002:
  Server Name       : xxx.xxx.xx
  Status            : FAILED
  Error:            : failure detecting data directory
bash-4.1$ barman show-backup xxx.xxx.xx 20140520T205254
Backup 20140520T205254:
  Server Name       : xxx.xxx.xx
  Status            : DONE
  PostgreSQL Version: 90302
  PGDATA directory  : /var/lib/pgsql/9.3/data

  Base backup information:
    Disk usage      : 10.1 GiB
    Timeline        : 1
    Begin WAL       : 00000001000000160000005A
    End WAL         : 00000001000000160000005A
    WAL number      : 1
    Begin time      : 2014-05-20 20:52:54.493173
    End time        : 2014-05-20 21:13:16.234241
    Begin Offset    : 40
    End Offset      : 2603104
    Begin XLOG      : 16/5A000028
    End XLOG        : 16/5A27B860

  WAL information:
    No of files     : 41
    Disk usage      : 211.6 MiB
    Last available  : 000000010000001600000083

  Catalog information:
    Retention Policy: VALID
    Previous Backup : 20140513T210335
    Next Backup     : - (this is the latest base backup)

After removing the failed backup the status is reported as it should

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.