Module: Snapshot

Includes:
Logging
Included in:
ElasticManager
Defined in:
lib/elastic_manager/snapshot.rb

Overview

Index snapshoting operations

Constant Summary

Constants included from Logging

Logging::SEVERITY_COLORS

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, #log, log_level, logger_for

Instance Method Details

#do_snapshot(indices) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/elastic_manager/snapshot.rb', line 33

def do_snapshot(indices)
  indices.each do |index|
    next if skip_index?(index, 'snapshot')

    response = @elastic.request(:get, "/_cat/indices/#{index}")

    if index_exist?(response)
      elastic_action_with_log('open_index', index) unless already?(response, 'open')
      elastic_action_with_log('delete_index', index) if elastic_action_with_log('snapshot_index', index)
    else
      log.warn "#{index} index not found"
    end
  end
end

#snapshotObject



48
49
50
51
52
53
54
# File 'lib/elastic_manager/snapshot.rb', line 48

def snapshot
  indices, date_from, date_to, daysago = prepare_vars
  prechecks(date_from, date_to)
  indices = snapshot_populate_indices(indices, date_from, date_to, daysago)
  log.debug indices.inspect
  do_snapshot(indices)
end

#snapshot_populate_indices(indices, date_from, date_to, daysago) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/elastic_manager/snapshot.rb', line 9

def snapshot_populate_indices(indices, date_from, date_to, daysago)
  result = []

  if indices.length == 1 && indices.first == '_all'
    result = @elastic.all_indices(date_from, date_to, daysago, nil, @config['settings']['box_types']['store'], @config)
  else
    if date_from.nil?
      result = @elastic.all_indices(date_from, date_to, daysago, nil, @config['settings']['box_types']['store'], @config).select { |r| r.start_with?(*indices) }
    else
      date_from.upto(date_to) do |date|
        indices.each do |index|
          date_formatted = date.to_s.tr('-', '.')
          result << "#{index}-#{date_formatted}"
        end
      end
    end
  end

  return result unless result.empty?

  log.fatal 'no indices for work'
  exit 1
end