Class: Backup::Storage::Sndacs

Inherits:
Base
  • Object
show all
Defined in:
lib/backup/storage/sndacs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, storage_id = nil, &block) ⇒ Sndacs

Returns a new instance of Sndacs.



12
13
14
15
16
17
18
# File 'lib/backup/storage/sndacs.rb', line 12

def initialize(model, storage_id = nil, &block)
  super(model, storage_id)

  @bucket ||= 'backups'

  instance_eval(&block) if block_given?
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



8
9
10
# File 'lib/backup/storage/sndacs.rb', line 8

def access_key
  @access_key
end

#access_secretObject

Returns the value of attribute access_secret.



8
9
10
# File 'lib/backup/storage/sndacs.rb', line 8

def access_secret
  @access_secret
end

#bucketObject

Returns the value of attribute bucket.



9
10
11
# File 'lib/backup/storage/sndacs.rb', line 9

def bucket
  @bucket
end

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/backup/storage/sndacs.rb', line 10

def path
  @path
end

Instance Method Details

#remove!(pkg) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/backup/storage/sndacs.rb', line 20

def remove!(pkg)
  remote_path = remote_path_for(pkg)
  package.filenames.each do |remote_file|
    Logger.info "#{storage_name} started removing " +
        "'#{ remote_file }' from bucket '#{ bucket }'."
    key = File.join(remote_path, remote_file)
    res = bucket_service.objects.find(key).destroy
    unless res == true
      raise "delete '#{key}' failed"
    end
  end
end

#transfer!Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/backup/storage/sndacs.rb', line 33

def transfer!
  remote_path = remote_path_for(@package)
  package.filenames.each do |filename|
    Logger.info "#{storage_name} started transferring " +
        "'#{ filename }'."
    key = File.join(remote_path, filename)
    o = bucket_service.objects.build(key)
    o.content = open(File.join(Config.tmp_path, filename))
    res = o.save
    raise "upload '#{filename}' failed" unless res == true
    Logger.info "file uploaded to bucket:#{bucket}, key:#{key}"
  end
end