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

Constructor Details

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

Takes the name of the archive and the configuration block



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

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

  @name             ||= "ldap_backup"
  @use_sudo         ||= false
  @slapcat_args     ||= []
  @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



8
9
10
# File 'lib/backup/database/openldap.rb', line 8

def name
  @name
end

#slapcat_argsObject

Additional slapcat options



22
23
24
# File 'lib/backup/database/openldap.rb', line 22

def slapcat_args
  @slapcat_args
end

#slapcat_confObject

Stores the location of the slapd.conf or slapcat confdir



18
19
20
# File 'lib/backup/database/openldap.rb', line 18

def slapcat_conf
  @slapcat_conf
end

#slapcat_utilityObject

Path to slapcat utility (optional)



26
27
28
# File 'lib/backup/database/openldap.rb', line 26

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



14
15
16
# File 'lib/backup/database/openldap.rb', line 14

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’



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

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