Class: Mys3ql::S3

Inherits:
Object
  • Object
show all
Includes:
Shell
Defined in:
lib/mys3ql/s3.rb

Instance Method Summary collapse

Methods included from Shell

#log, #run

Constructor Details

#initialize(config) ⇒ S3

Returns a new instance of S3.



8
9
10
11
# File 'lib/mys3ql/s3.rb', line 8

def initialize(config)
  @config = config
  Fog::Logger[:warning] = nil
end

Instance Method Details

#delete_bin_logsObject



23
24
25
26
27
28
# File 'lib/mys3ql/s3.rb', line 23

def delete_bin_logs
  each_bin_log do |file|
    file.destroy
    log "s3: deleted #{file.key}"
  end
end

#each_bin_log(&block) ⇒ Object



30
31
32
33
34
# File 'lib/mys3ql/s3.rb', line 30

def each_bin_log(&block)
  bucket.files.all(:prefix => "#{bin_logs_prefix}").sort_by { |file| file.key[/\d+/].to_i }.each do |file|
    yield file
  end
end

#retrieve(s3_file, local_file) ⇒ Object



36
37
38
39
# File 'lib/mys3ql/s3.rb', line 36

def retrieve(s3_file, local_file)
  key = (s3_file == :latest) ? key_for(:latest) : s3_file.key
  get key, local_file
end

#store(file, dump = true) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/mys3ql/s3.rb', line 13

def store(file, dump = true)
  key = key_for(dump ? :dump : :bin_log, file)
  s3_file = save file, key
  if dump && s3_file
    copy_key = key_for :latest
    s3_file.copy @config.bucket, copy_key
    log "s3: copied #{key} to #{copy_key}"
  end
end