xaviershay-db2s3 0.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +10 -4
- data/db2s3.gemspec +2 -1
- data/lib/db2s3/tasks.rb +1 -0
- data/lib/db2s3.rb +5 -3
- data/rails/init.rb +1 -1
- data/spec/db2s3_spec.rb +12 -2
- data/tasks/tasks.rake +8 -3
- metadata +2 -1
data/README
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
DB2S3 - A rails plugin to backup Mysql to Amazon S3
|
2
2
|
---------------------------------------------------
|
3
|
-
|
4
|
-
|
5
|
-
gem install aws-s3
|
3
|
+
You're looking at a monthly spend of four cents
|
4
|
+
So pony up you cheap bastard, and store your backups on S3
|
6
5
|
|
7
6
|
Usage:
|
8
|
-
|
7
|
+
# In config/environment.rb
|
8
|
+
config.gem "xaviershay-db2s3", :lib => "db2s3", :source => "http://gems.github.com"
|
9
|
+
|
10
|
+
# In Rakefile
|
11
|
+
require 'db2s3/tasks'
|
12
|
+
|
9
13
|
# In config/initializers/db2s3.rb
|
10
14
|
DB2S3::Config.instance_eval do
|
11
15
|
S3 = {
|
@@ -16,6 +20,8 @@ Usage:
|
|
16
20
|
end
|
17
21
|
# DB credentials are read from your rails environment
|
18
22
|
|
23
|
+
rake gems:install
|
24
|
+
|
19
25
|
# Add to your crontab or whatever
|
20
26
|
rake db2s3:backup:full
|
21
27
|
rake db2s3:backup:incremental # Unimplemented
|
data/db2s3.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{db2s3}
|
5
|
-
s.version = "0.2"
|
5
|
+
s.version = "0.2.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Xavier Shay"]
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
init.rb
|
17
17
|
lib
|
18
18
|
lib/db2s3.rb
|
19
|
+
lib/db2s3/tasks.rb
|
19
20
|
rails
|
20
21
|
rails/init.rb
|
21
22
|
spec
|
data/lib/db2s3/tasks.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/../../tasks/*.rake"].each { |ext| load ext }
|
data/lib/db2s3.rb
CHANGED
@@ -23,14 +23,16 @@ class DB2S3
|
|
23
23
|
transfer_dollars_per_byte_per_month = 0.10 / 1024.0 / 1024.0 / 1024.0
|
24
24
|
full_dumps_per_month = 30
|
25
25
|
|
26
|
-
storage_cost = dump_file.size * storage_dollars_per_byte_per_month
|
27
|
-
transfer_cost = dump_file.size * full_dumps_per_month * transfer_dollars_per_byte_per_month
|
26
|
+
storage_cost = (dump_file.size * storage_dollars_per_byte_per_month * 100).ceil / 100.0
|
27
|
+
transfer_cost = (dump_file.size * full_dumps_per_month * transfer_dollars_per_byte_per_month * 100).ceil / 100.0
|
28
|
+
requests_cost = 0.02 # TODO: Actually calculate this, with incremental backups could be more
|
28
29
|
|
29
30
|
{
|
30
31
|
:db_size => dump_file.size,
|
31
32
|
:storage_cost => storage_cost,
|
32
33
|
:transfer_cost => transfer_cost,
|
33
|
-
:total_cost => storage_cost + transfer_cost,
|
34
|
+
:total_cost => storage_cost + transfer_cost + requests_cost,
|
35
|
+
:requests_cost => requests_cost,
|
34
36
|
:full_backups_per_month => full_dumps_per_month
|
35
37
|
}
|
36
38
|
end
|
data/rails/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/db2s3')
|
data/spec/db2s3_spec.rb
CHANGED
@@ -28,11 +28,21 @@ describe 'db2s3' do
|
|
28
28
|
db2s3.stub!(:dump_db).and_return(stub("dump file", :size => 1024 * 1024 * 1024))
|
29
29
|
metrics = db2s3.metrics
|
30
30
|
metrics.should == {
|
31
|
-
:storage_cost => 0.15, # 15c/GB-Month, we're only storing one backup
|
31
|
+
:storage_cost => 0.15, # 15c/GB-Month rounded up to nearest cent, we're only storing one backup
|
32
32
|
:transfer_cost => 3.0, # 10c/GB-Month * 30 backups
|
33
33
|
:db_size => 1024 * 1024 * 1024, # 1 GB
|
34
|
-
:total_cost => 3.
|
34
|
+
:total_cost => 3.17,
|
35
|
+
:requests_cost => 0.02,
|
35
36
|
:full_backups_per_month => 30 # Default 1 backup/day
|
36
37
|
}
|
37
38
|
end
|
39
|
+
|
40
|
+
it 'rounds transfer cost metric up to nearest cent' do
|
41
|
+
db2s3 = DB2S3.new
|
42
|
+
# 1 KB DB
|
43
|
+
db2s3.stub!(:dump_db).and_return(stub("dump file", :size => 1024))
|
44
|
+
metrics = db2s3.metrics
|
45
|
+
metrics[:storage_cost].should == 0.01
|
46
|
+
metrics[:transfer_cost].should == 0.01
|
47
|
+
end
|
38
48
|
end
|
data/tasks/tasks.rake
CHANGED
@@ -15,15 +15,20 @@ namespace :db2s3 do
|
|
15
15
|
s.sub(/\.?0*$/, units[e])
|
16
16
|
end
|
17
17
|
|
18
|
+
def format_cost(cost)
|
19
|
+
"%.2f" % [cost]
|
20
|
+
end
|
21
|
+
|
18
22
|
metrics = DB2S3.new.metrics
|
19
23
|
puts <<-EOS
|
20
24
|
Estimates only, does not take into account metadata overhead
|
21
25
|
|
22
26
|
DB Size: #{format_size(metrics[:db_size])}
|
23
27
|
Full backups/month: #{metrics[:full_backups_per_month]}
|
24
|
-
Storage Cost $US: #{metrics[:storage_cost]}
|
25
|
-
Transfer Cost $US: #{metrics[:transfer_cost]}
|
26
|
-
|
28
|
+
Storage Cost $US: #{format_cost(metrics[:storage_cost])}
|
29
|
+
Transfer Cost $US: #{format_cost(metrics[:transfer_cost])}
|
30
|
+
Requests Cost $US: #{format_cost(metrics[:requests_cost])}
|
31
|
+
Total Cost $US: #{format_cost(metrics[:total_cost])}
|
27
32
|
EOS
|
28
33
|
end
|
29
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xaviershay-db2s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Shay
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- init.rb
|
38
38
|
- lib
|
39
39
|
- lib/db2s3.rb
|
40
|
+
- lib/db2s3/tasks.rb
|
40
41
|
- rails
|
41
42
|
- rails/init.rb
|
42
43
|
- spec
|