Class: PoringBackup::Storages::S3

Inherits:
PoringBackup::Storage show all
Defined in:
lib/poring_backup/storages/s3.rb

Instance Attribute Summary collapse

Attributes inherited from PoringBackup::Storage

#setting

Instance Method Summary collapse

Constructor Details

#initialize(setting, &block) ⇒ S3

Returns a new instance of S3.



7
8
9
10
# File 'lib/poring_backup/storages/s3.rb', line 7

def initialize setting, &block
  super
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#bucket_objectObject (readonly)

Returns the value of attribute bucket_object.



5
6
7
# File 'lib/poring_backup/storages/s3.rb', line 5

def bucket_object
  @bucket_object
end

#s3Object (readonly)

Returns the value of attribute s3.



5
6
7
# File 'lib/poring_backup/storages/s3.rb', line 5

def s3
  @s3
end

Instance Method Details

#access_key_id(key) ⇒ Object



20
21
22
# File 'lib/poring_backup/storages/s3.rb', line 20

def access_key_id key
  @access_key_id = key
end

#bucket(name) ⇒ Object



28
29
30
# File 'lib/poring_backup/storages/s3.rb', line 28

def bucket name
  @bucket = name
end

#path(name) ⇒ Object



36
37
38
# File 'lib/poring_backup/storages/s3.rb', line 36

def path name
  @path = name
end

#region(name) ⇒ Object



32
33
34
# File 'lib/poring_backup/storages/s3.rb', line 32

def region name
  @region = name
end

#secret_access_key(key) ⇒ Object



24
25
26
# File 'lib/poring_backup/storages/s3.rb', line 24

def secret_access_key key
  @secret_access_key = key
end

#uploadObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/poring_backup/storages/s3.rb', line 40

def upload
  PoringBackup.logger.info "S3 processing"
  setting.databases.each do |db|
    s3_path = "#{@path}/#{db.file_path}"
    object = bucket_object.object(s3_path)
    success = object.upload_file(db.tmp_file_path)
    if success
      PoringBackup.logger.info "#{' '*3}uploaded: #{s3_path}"
    else
      PoringBackup.logger.warn "#{' '*3}uploaded failure: #{db.tmp_file_path}"
    end
  end
  PoringBackup.logger.info "#{' '*3}finished"
end