Class: Backup::Database::OpenLDAP

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

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Attributes inherited from Base

#database_id, #dump_path, #model

Instance Method Summary collapse

Methods included from Config::Helpers

included

Methods included from Utilities::Helpers

#utility_remote

Constructor Details

#initialize(model, database_id = nil, &block) ⇒ OpenLDAP

Takes the name of the archive and the configuration block



32
33
34
35
36
37
38
39
40
41
# File 'lib/backup/database/openldap.rb', line 32

def initialize(model, database_id = nil, &block)
  super
  instance_eval(&block) if block_given?

  @name             ||= 'ldap_backup'
  @use_sudo         ||= false
  @slapcat_args     ||= Array.new
  @slapcat_utility  ||= utility(:slapcat)
  @slapcat_conf     ||= '/etc/ldap/slapd.d'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Backup::Config::Helpers

Instance Attribute Details

#nameObject

Name of the ldap backup



10
11
12
# File 'lib/backup/database/openldap.rb', line 10

def name
  @name
end

#slapcat_argsObject

Additional slapcat options



24
25
26
# File 'lib/backup/database/openldap.rb', line 24

def slapcat_args
  @slapcat_args
end

#slapcat_confObject

Stores the location of the slapd.conf or slapcat confdir



20
21
22
# File 'lib/backup/database/openldap.rb', line 20

def slapcat_conf
  @slapcat_conf
end

#slapcat_utilityObject

Path to slapcat utility (optional)



28
29
30
# File 'lib/backup/database/openldap.rb', line 28

def slapcat_utility
  @slapcat_utility
end

#use_sudoObject

run slapcat under sudo if needed make sure to set SUID on a file, to let you run the file with permissions of file owner eg. sudo chmod u+s /usr/sbin/slapcat



16
17
18
# File 'lib/backup/database/openldap.rb', line 16

def use_sudo
  @use_sudo
end

Instance Method Details

#perform!Object

Performs the slapcat command and outputs the data to the specified path based on the ‘trigger’



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/backup/database/openldap.rb', line 46

def perform!
  super

  pipeline = Pipeline.new
  dump_ext = 'ldif'

  pipeline << slapcat
  if @model.compressor
    @model.compressor.compress_with do |command, ext|
      pipeline << command
      dump_ext << ext
    end
  end

  pipeline << "#{ utility(:cat) } > " +
      "'#{ File.join(dump_path, dump_filename) }.#{ dump_ext }'"

  pipeline.run
  if pipeline.success?
    log!(:finished)
  else
    raise Error, "Dump Failed!\n" + pipeline.error_messages
  end
end