Class: Backup::Database::Riak

Inherits:
Base
  • Object
show all
Defined in:
lib/backup/database/riak.rb

Constant Summary

Constants included from CLI::Helpers

CLI::Helpers::UTILITY

Instance Attribute Summary collapse

Attributes inherited from Base

#utility_path

Instance Method Summary collapse

Methods included from Configuration::Helpers

#clear_defaults!, #load_defaults!

Methods included from CLI::Helpers

#command_name, #raise_if_command_failed!, #run, #utility

Constructor Details

#initialize(model, &block) ⇒ Riak

Creates a new instance of the Riak adapter object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/backup/database/riak.rb', line 25

def initialize(model, &block)
  super(model)

  instance_eval(&block) if block_given?

  if @utility_path
    Logger.warn "[DEPRECATED] " +
      "Database::Riak#utility_path has been deprecated.\n" +
      "  Use Database::Riak#riak_admin_utility instead."
    @riak_admin_utility ||= @utility_path
  end
  @riak_admin_utility ||= utility('riak-admin')
end

Instance Attribute Details

Cookie is the Erlang cookie/shared secret used to connect to the node.



17
18
19
# File 'lib/backup/database/riak.rb', line 17

def cookie
  @cookie
end

#nameObject

Name is the name of the backup



9
10
11
# File 'lib/backup/database/riak.rb', line 9

def name
  @name
end

#nodeObject

Node is the node from which to perform the backup.



13
14
15
# File 'lib/backup/database/riak.rb', line 13

def node
  @node
end

#riak_admin_utilityObject

Path to riak-admin utility (optional)



21
22
23
# File 'lib/backup/database/riak.rb', line 21

def riak_admin_utility
  @riak_admin_utility
end

Instance Method Details

#perform!Object

Performs the riak-admin command and outputs the data to the specified path based on the ‘trigger’



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/backup/database/riak.rb', line 42

def perform!
  super
  # have to make riak the owner since the riak-admin tool runs
  # as the riak user in a default setup.
  FileUtils.chown_R('riak', 'riak', @dump_path)

  backup_file = File.join(@dump_path, name)
  run("#{ riakadmin } #{ backup_file } node")

  if @model.compressor
    @model.compressor.compress_with do |command, ext|
      run("#{ command } -c #{ backup_file } > #{ backup_file + ext }")
      FileUtils.rm_f(backup_file)
    end
  end
end