Class: DB2S3

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

Defined Under Namespace

Classes: Config, S3Store

Instance Method Summary collapse

Constructor Details

#initializeDB2S3

Returns a new instance of DB2S3.



8
9
# File 'lib/db2s3.rb', line 8

def initialize
end

Instance Method Details

#full_backupObject



11
12
13
14
15
# File 'lib/db2s3.rb', line 11

def full_backup
  file_name = "dump-#{db_credentials[:database]}-#{Time.now.utc.strftime("%Y%m%d%H%M")}.sql.gz"
  store.store(file_name, open(dump_db.path))
  store.store(most_recent_dump_file_name, file_name)
end

#metricsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/db2s3.rb', line 23

def metrics
  dump_file = dump_db

  storage_dollars_per_byte_per_month  = 0.15 / 1024.0 / 1024.0 / 1024.0
  transfer_dollars_per_byte_per_month = 0.10 / 1024.0 / 1024.0 / 1024.0
  full_dumps_per_month = 30

  storage_cost = (dump_file.size * storage_dollars_per_byte_per_month * 100).ceil / 100.0
  transfer_cost = (dump_file.size * full_dumps_per_month * transfer_dollars_per_byte_per_month * 100).ceil / 100.0
  requests_cost = 0.02 # TODO: Actually calculate this, with incremental backups could be more

  {
    :db_size       => dump_file.size,
    :storage_cost  => storage_cost,
    :transfer_cost => transfer_cost,
    :total_cost    => storage_cost + transfer_cost + requests_cost,
    :requests_cost => requests_cost,
    :full_backups_per_month => full_dumps_per_month
  }
end

#restoreObject



17
18
19
20
21
# File 'lib/db2s3.rb', line 17

def restore
  dump_file_name = store.fetch(most_recent_dump_file_name).read
  file = store.fetch(dump_file_name)
  run "gunzip -c #{file.path} | mysql #{mysql_options}"
end