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.



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

def initialize
end

Instance Method Details

#full_backupObject



10
11
12
# File 'lib/db2s3.rb', line 10

def full_backup
  store.store("dump-#{db_credentials[:database]}.sql.gz", open(dump_db.path))
end

#metricsObject



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

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
  transfer_cost = dump_file.size * full_dumps_per_month * transfer_dollars_per_byte_per_month

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

#restoreObject



14
15
16
17
# File 'lib/db2s3.rb', line 14

def restore
  file = store.fetch("dump-#{db_credentials[:database]}.sql.gz")
  run "gunzip -c #{file.path} | mysql #{mysql_options}"
end