Class: Cryo
Constant Summary collapse
- VERSION =
"0.0.3"
Instance Attribute Summary collapse
-
#key ⇒ Object
HOST = ‘hostname`.chomp!.
-
#logger ⇒ Object
HOST = ‘hostname`.chomp!.
-
#md5 ⇒ Object
HOST = ‘hostname`.chomp!.
-
#options ⇒ Object
HOST = ‘hostname`.chomp!.
-
#s3 ⇒ Object
HOST = ‘hostname`.chomp!.
-
#sns ⇒ Object
HOST = ‘hostname`.chomp!.
Instance Method Summary collapse
- #archive_and_purge ⇒ Object
- #backup! ⇒ Object
- #get_snapshot(snapshot) ⇒ Object
-
#initialize(options = {}) ⇒ Cryo
constructor
A new instance of Cryo.
- #list_archives ⇒ Object
- #list_snapshots ⇒ Object
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(={}) self. = self.logger = Logger.new(STDERR) logger.level = Logger::DEBUG # save start time for backup @database = Database.create() \ unless [:type] == 'list' or [:type] == 'get' @store = Store.create(.merge(type: 's3',time: @time)) @message = Message.create(.merge(type: 'sns')) @snapshot_prefix = [:snapshot_prefix] @archive_prefix = [:archive_prefix] @key = get_timstamped_key_name @snapshot_frequency = [:snapshot_frequency] @archive_frequency = [:archive_frequency] @snapshot_period = [:snapshot_period] @snapshot_bucket = [:snapshot_bucket] @archive_bucket = [:archive_bucket] @tmp_path = [:tmp_path] end |
Instance Attribute Details
#key ⇒ Object
HOST = ‘hostname`.chomp!
17 18 19 |
# File 'lib/cryo.rb', line 17 def key @key end |
#logger ⇒ Object
HOST = ‘hostname`.chomp!
17 18 19 |
# File 'lib/cryo.rb', line 17 def logger @logger end |
#md5 ⇒ Object
HOST = ‘hostname`.chomp!
17 18 19 |
# File 'lib/cryo.rb', line 17 def md5 @md5 end |
#options ⇒ Object
HOST = ‘hostname`.chomp!
17 18 19 |
# File 'lib/cryo.rb', line 17 def @options end |
#s3 ⇒ Object
HOST = ‘hostname`.chomp!
17 18 19 |
# File 'lib/cryo.rb', line 17 def s3 @s3 end |
#sns ⇒ Object
HOST = ‘hostname`.chomp!
17 18 19 |
# File 'lib/cryo.rb', line 17 def sns @sns end |
Instance Method Details
#archive_and_purge ⇒ Object
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: [: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_archives ⇒ Object
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_snapshots ⇒ Object
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 |