Class: Elasticsearch::Snapshot::Snapshot
- Defined in:
- lib/elasticsearch/snapshot/snapshot.rb
Constant Summary
Constants inherited from Task
Task::NON_RESTORABLE_INDICES_REGEX
Instance Attribute Summary collapse
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
-
#initialize(cluster, repo) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #perform ⇒ Object
Constructor Details
#initialize(cluster, repo) ⇒ Snapshot
Returns a new instance of Snapshot.
6 7 8 9 |
# File 'lib/elasticsearch/snapshot/snapshot.rb', line 6 def initialize(cluster, repo) @cluster = cluster @repo = repo end |
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
4 5 6 |
# File 'lib/elasticsearch/snapshot/snapshot.rb', line 4 def cluster @cluster end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
4 5 6 |
# File 'lib/elasticsearch/snapshot/snapshot.rb', line 4 def repo @repo end |
Instance Method Details
#perform ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/elasticsearch/snapshot/snapshot.rb', line 11 def perform list_indexes_to_backup = JSON(open(command_list_indexes_to_backup(cluster)).read)['indices'].keys.delete_if { |i| i =~ NON_RESTORABLE_INDICES_REGEX } info "Snapshotting indexes: #{list_indexes_to_backup.join(', ')}" snapshot_pipe = IO.popen command_take_a_snapshot(cluster, repo) + %Q( -d '{"indices": "#{list_indexes_to_backup.join(',')}","include_global_state":false}') Process.waitall snapshot_result = snapshot_pipe.readlines raise if snapshot_result.length > 1 snapshot_result = JSON.load snapshot_result.first if snapshot_result.keys.include? 'error' error snapshot_result['error'] else raise unless snapshot_result['snapshot'] if snapshot_result['snapshot']['state'] == 'SUCCESS' info "Snapshot took #{snapshot_result['snapshot']['duration_in_millis']} ms" else error "Snapshot failed: #{snapshot_result['failures'].join(' ')}" end end rescue error "Snapshot aborted: #{$!}" end |