Class: Cryo

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/cryo.rb,
lib/cryo/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#delete_file, #get_age_from_key_name, #get_tempfile, #get_timstamped_key_name, #get_utc_time, #get_utc_time_from_key_name, #get_utc_timestamp, #gzip_file, #need_to_archive?, #safe_run, #ungzip_file, #verify_system_dependency

Constructor Details

#initialize(options = {}) ⇒ Cryo

Returns a new instance of Cryo.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cryo.rb', line 19

def initialize(options={})
  self.options = options
  self.logger = Logger.new(STDERR)
  logger.level = Logger::DEBUG

  get_utc_timestamp # save start time for backup

  @database = Database.create(options) \
    unless options[:type] == 'list' or options[:type] == 'get'
  @store = Store.create(options.merge(type: 's3',time: @time))
  @message = Message.create(options.merge(type: 'sns'))
  @snapshot_prefix = options[:snapshot_prefix]
  @archive_prefix = options[:archive_prefix]
  @key = get_timstamped_key_name
  @snapshot_frequency = options[:snapshot_frequency]
  @archive_frequency = options[:archive_frequency]
  @snapshot_period = options[:snapshot_period]
  @snapshot_bucket = options[:snapshot_bucket]
  @archive_bucket = options[:archive_bucket]
  @tmp_path = options[:tmp_path]
end

Instance Attribute Details

#keyObject

HOST = ‘hostname`.chomp!



17
18
19
# File 'lib/cryo.rb', line 17

def key
  @key
end

#loggerObject

HOST = ‘hostname`.chomp!



17
18
19
# File 'lib/cryo.rb', line 17

def logger
  @logger
end

#md5Object

HOST = ‘hostname`.chomp!



17
18
19
# File 'lib/cryo.rb', line 17

def md5
  @md5
end

#optionsObject

HOST = ‘hostname`.chomp!



17
18
19
# File 'lib/cryo.rb', line 17

def options
  @options
end

#s3Object

HOST = ‘hostname`.chomp!



17
18
19
# File 'lib/cryo.rb', line 17

def s3
  @s3
end

#snsObject

HOST = ‘hostname`.chomp!



17
18
19
# File 'lib/cryo.rb', line 17

def sns
  @sns
end

Instance Method Details

#archive_and_purgeObject



66
67
68
69
70
# File 'lib/cryo.rb', line 66

def archive_and_purge()
  logger.info "archiving and purging..."
  @store.archive_and_purge()
  logger.info "done archiving and purging :)"
end

#backup!Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cryo.rb', line 42

def backup!()
  if @database.respond_to? 'get_gzipped_backup'
    logger.info "getting compressed backup"
    compressed_backup = @database.get_gzipped_backup
    logger.info "got backup in #{(get_utc_time - @time).round 2} seconds"
  else
    logger.info "taking backup..."
    backup_file = @database.get_backup
    logger.info "got backup in #{(get_utc_time - @time).round 2} seconds"

    timer = get_utc_time
    logger.info "compressing backup..."
    compressed_backup = gzip_file backup_file
    logger.info "compressed backup in #{(get_utc_time - timer).round 2} seconds"
  end

  timer = get_utc_time
  logger.info "storing backup..."
  @store.put(content: Pathname.new(compressed_backup), bucket: options[:snapshot_bucket],key: @key)
  logger.info "upload took #{(get_utc_time - timer).round 2} seconds"

  logger.info "completed entire backup in #{(get_utc_time - @time).round 2} seconds :)"
end

#get_snapshot(snapshot) ⇒ Object



84
85
86
87
88
# File 'lib/cryo.rb', line 84

def get_snapshot(snapshot)
  basename = File.basename snapshot
  puts "getting #{snapshot} and saving it in #{File.join(Dir.pwd,basename)}"
  @store.get(bucket: @snapshot_bucket,key: snapshot,file: basename)
end

#list_archivesObject



78
79
80
81
82
# File 'lib/cryo.rb', line 78

def list_archives
  archive_list = @store.get_bucket_listing(bucket: @archive_bucket, prefix: @archive_prefix)
  puts "here is what I see in the archive bucket:"
  archive_list.each { |i| puts "  #{i.key}"}
end

#list_snapshotsObject



72
73
74
75
76
# File 'lib/cryo.rb', line 72

def list_snapshots
  snapshot_list = @store.get_bucket_listing(bucket: @snapshot_bucket, prefix: @snapshot_prefix)
  puts "here is what I see in the snapshot bucket:"
  snapshot_list.each { |i| puts "  #{i.key}"}
end