Class: Snapshooter::Base

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/snapshooter/base.rb

Direct Known Subclasses

Storage::S3

Instance Method Summary collapse

Methods included from Log

#with_log

Constructor Details

#initialize(id, storage = :local) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/snapshooter/base.rb', line 5

def initialize(id, storage=:local)
  @id = id
  case storage
  when :s3
    @storage = Storage::S3.new
  when :local
    @storage = Storage::Local.new
  else
    raise "Unknown storage type: #{storage}"
  end
end

Instance Method Details

#restoreObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/snapshooter/base.rb', line 17

def restore
  datastores.each do |datastore|
    filename = "#{@id}-#{datastore.filename}"

    @storage.get filename do |file|
      with_log("Restore from #{filename}") do
        datastore.restore(file)
      end
    end
  end
end

#snapshot!Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/snapshooter/base.rb', line 29

def snapshot!
  datastores.each do |datastore|
    filename = "#{@id}-#{datastore.filename}"

    @storage.save filename do |tmp_file|
      with_log "Snapshot to #{filename}" do
        datastore.snapshot tmp_file
      end
    end
  end
end