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.



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

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

Instance Method Details

#pathObject



19
20
21
# File 'lib/backup/storage/sndacs.rb', line 19

def path
  ''
end

#remove!(pkg) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/backup/storage/sndacs.rb', line 23

def remove!(pkg)
  remote_path = remote_path_for(pkg)
  transferred_files_for(pkg) do |local_file, remote_file|
    Logger.info "#{storage_name} started removing " +
        "'#{ local_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



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/backup/storage/sndacs.rb', line 36

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