Class: S3snapshot::SyncOp

Inherits:
Object
  • Object
show all
Defined in:
lib/s3snapshot/sync_op.rb

Direct Known Subclasses

BackupManager, DirDownload, DirUpload

Constant Summary collapse

COMPLETE_FILE =

Constant for the file that will be present with the complete timestamp if a directory was successfully backed up

"s3snapshot"
COMPLETE_EXTENSION =
"complete_marker"
COMPLETE_MARKER =
"#{COMPLETE_FILE}.#{COMPLETE_EXTENSION}"

Instance Method Summary collapse

Constructor Details

#initialize(aws_id, aws_key, bucket_name) ⇒ SyncOp



21
22
23
24
25
# File 'lib/s3snapshot/sync_op.rb', line 21

def initialize(aws_id, aws_key, bucket_name)
  @bucket_name = bucket_name
  @aws_id = aws_id
  @aws_key = aws_key
end

Instance Method Details

#awsObject

Return the cached aws connection or create a new one



30
31
32
# File 'lib/s3snapshot/sync_op.rb', line 30

def aws
  @aws ||= Fog::Storage.new(:provider => 'AWS', :persistent => false, :aws_access_key_id => @aws_id, :aws_secret_access_key => @aws_key)
end

#bucketObject

Get the cached bucket or create the new one



37
38
39
40
# File 'lib/s3snapshot/sync_op.rb', line 37

def bucket
  #      @bucket ||=  aws.directories.get(@bucket_name)
  aws.directories.get(@bucket_name)
end

#complete_path(prefix, time) ⇒ Object

The path to the complete file with the given prefix and time



51
52
53
# File 'lib/s3snapshot/sync_op.rb', line 51

def complete_path(prefix, time)
  "#{timepath(prefix, time)}/#{COMPLETE_MARKER}"
end

#complete_prefix(prefix, time) ⇒ Object

Constructs a prefix in the format of [prefix]/[iso time]/complete_file



57
58
59
# File 'lib/s3snapshot/sync_op.rb', line 57

def complete_prefix(prefix, time)
  "#{timepath(prefix, time)}/#{COMPLETE_FILE}"
end

#timepath(prefix, time) ⇒ Object

Generate the time path. If a prefix is specified the format is <prefix>/<timestamp> otherwise it is timestamp. All timestamps are in iso 8601 format and in the UTC time zone



43
44
45
# File 'lib/s3snapshot/sync_op.rb', line 43

def timepath(prefix, time)
 "#{prefix}/#{time.utc.iso8601}"
end