Class: Siba::Destination::AwsS3::Init

Inherits:
Object
  • Object
show all
Includes:
LoggerPlug
Defined in:
lib/siba-destination-aws-s3/init.rb

Constant Summary collapse

DEFAULT_ACCESS_KEY_ID_ENV_NAME =
"SIBA_AMAZON_ACCESS_KEY_ID"
DEFAULT_SECRET_KEY_ENV_NAME =
"SIBA_AMAZON_SECRET_ACCESS_KEY"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Init

Returns a new instance of Init.

Raises:

  • (Siba::CheckError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/siba-destination-aws-s3/init.rb', line 15

def initialize(options)  
  bucket = Siba::SibaCheck.options_string options, "bucket"

  access_key_id_name = "access_key_id"
  secret_key_name = "secret_access_key"
  access_key_id = Siba::SibaCheck.options_string options, access_key_id_name, true, ENV[DEFAULT_ACCESS_KEY_ID_ENV_NAME]
  secret_key = Siba::SibaCheck.options_string options, secret_key_name, true, ENV[DEFAULT_SECRET_KEY_ENV_NAME]

  raise Siba::CheckError, "Missing '#{access_key_id_name}' option" if access_key_id.nil?
  raise Siba::CheckError, "Missing '#{secret_key_name}' option" if secret_key.nil?

  logger.info "Checking connection to Amazon S3"
  @cloud = Siba::Destination::AwsS3::Cloud.new bucket, access_key_id, secret_key
end

Instance Attribute Details

#cloudObject

Returns the value of attribute cloud.



13
14
15
# File 'lib/siba-destination-aws-s3/init.rb', line 13

def cloud
  @cloud
end

Instance Method Details

#backup(path_to_backup_file) ⇒ Object



30
31
32
# File 'lib/siba-destination-aws-s3/init.rb', line 30

def backup(path_to_backup_file) 
  @cloud.upload path_to_backup_file
end

#get_backups_list(backup_name) ⇒ Object

Returns an array of two-element arrays:

backup_file_name, modification_time


36
37
38
39
# File 'lib/siba-destination-aws-s3/init.rb', line 36

def get_backups_list(backup_name)
  logger.info "Getting the list of backups from Amazon S3"
  @cloud.get_backups_list backup_name
end

#restore(backup_name, dir) ⇒ Object

Put backup file into dir



42
43
44
45
# File 'lib/siba-destination-aws-s3/init.rb', line 42

def restore(backup_name, dir)
  logger.info "Downloading backup from Amazon S3"
  @cloud.restore_backup_to_dir backup_name, dir
end