db2s3 0.2.5 → 0.2.6
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/.gitignore +2 -0
- data/HISTORY +6 -0
- data/README +1 -1
- data/VERSION +1 -0
- data/lib/db2s3.rb +5 -25
- data/spec/db2s3_spec.rb +0 -24
- data/tasks/tasks.rake +19 -24
- metadata +3 -3
- data/db2s3.gemspec +0 -55
data/.gitignore
CHANGED
data/HISTORY
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.2.6
|
2
|
+
- Remove metrics task, since it was far too inaccurate
|
3
|
+
- Add statistics task to show you the size of your tables
|
4
|
+
- Only add username to mysql command line if provided in database.yml
|
5
|
+
0.2.5
|
6
|
+
- Use host provided in database.yml
|
1
7
|
0.2.4 (2 Sep 2009)
|
2
8
|
- Fix credentials bug
|
3
9
|
0.2.3
|
data/README
CHANGED
@@ -5,7 +5,7 @@ So pony up you cheap bastard, and store your backups on S3
|
|
5
5
|
|
6
6
|
Usage:
|
7
7
|
# In config/environment.rb
|
8
|
-
config.gem "
|
8
|
+
config.gem "db2s3", :source => "http://gemcutter.org"
|
9
9
|
|
10
10
|
# In Rakefile
|
11
11
|
require 'db2s3/tasks'
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.6
|
data/lib/db2s3.rb
CHANGED
@@ -20,32 +20,11 @@ class DB2S3
|
|
20
20
|
run "gunzip -c #{file.path} | mysql #{mysql_options}"
|
21
21
|
end
|
22
22
|
|
23
|
-
def metrics
|
24
|
-
dump_file = dump_db
|
25
|
-
|
26
|
-
storage_dollars_per_byte_per_month = 0.15 / 1024.0 / 1024.0 / 1024.0
|
27
|
-
transfer_dollars_per_byte_per_month = 0.10 / 1024.0 / 1024.0 / 1024.0
|
28
|
-
full_dumps_per_month = 30
|
29
|
-
|
30
|
-
storage_cost = (dump_file.size * storage_dollars_per_byte_per_month * 100).ceil / 100.0
|
31
|
-
transfer_cost = (dump_file.size * full_dumps_per_month * transfer_dollars_per_byte_per_month * 100).ceil / 100.0
|
32
|
-
requests_cost = 0.02 # TODO: Actually calculate this, with incremental backups could be more
|
33
|
-
|
34
|
-
{
|
35
|
-
:db_size => dump_file.size,
|
36
|
-
:storage_cost => storage_cost,
|
37
|
-
:transfer_cost => transfer_cost,
|
38
|
-
:total_cost => storage_cost + transfer_cost + requests_cost,
|
39
|
-
:requests_cost => requests_cost,
|
40
|
-
:full_backups_per_month => full_dumps_per_month
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
23
|
private
|
45
24
|
|
46
25
|
def dump_db
|
47
26
|
dump_file = Tempfile.new("dump")
|
48
|
-
|
27
|
+
|
49
28
|
#cmd = "mysqldump --quick --single-transaction --create-options -u#{db_credentials[:user]} --flush-logs --master-data=2 --delete-master-logs"
|
50
29
|
cmd = "mysqldump --quick --single-transaction --create-options #{mysql_options}"
|
51
30
|
cmd += " | gzip > #{dump_file.path}"
|
@@ -55,7 +34,8 @@ class DB2S3
|
|
55
34
|
end
|
56
35
|
|
57
36
|
def mysql_options
|
58
|
-
cmd =
|
37
|
+
cmd = ''
|
38
|
+
cmd += " -u #{db_credentials[:username]} " unless db_credentials[:username].nil?
|
59
39
|
cmd += " -p'#{db_credentials[:password]}'" unless db_credentials[:password].nil?
|
60
40
|
cmd += " -h '#{db_credentials[:host]}'" unless db_credentials[:host].nil?
|
61
41
|
cmd += " #{db_credentials[:database]}"
|
@@ -74,7 +54,7 @@ class DB2S3
|
|
74
54
|
raise("error, process exited with status #{$?.exitstatus}") unless result
|
75
55
|
end
|
76
56
|
|
77
|
-
def db_credentials
|
57
|
+
def db_credentials
|
78
58
|
ActiveRecord::Base.connection.instance_eval { @config } # Dodgy!
|
79
59
|
end
|
80
60
|
|
@@ -98,7 +78,7 @@ class DB2S3
|
|
98
78
|
def fetch(file_name)
|
99
79
|
ensure_connected
|
100
80
|
AWS::S3::S3Object.find(file_name, bucket)
|
101
|
-
|
81
|
+
|
102
82
|
file = Tempfile.new("dump")
|
103
83
|
open(file.path, 'w') do |f|
|
104
84
|
AWS::S3::S3Object.stream(file_name, bucket) do |chunk|
|
data/spec/db2s3_spec.rb
CHANGED
@@ -23,28 +23,4 @@ describe 'db2s3' do
|
|
23
23
|
Person.find_by_name("Baxter").should_not be_nil
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
27
|
-
it 'provides estimated metrics' do
|
28
|
-
db2s3 = DB2S3.new
|
29
|
-
# 1 GB DB
|
30
|
-
db2s3.stub!(:dump_db).and_return(stub("dump file", :size => 1024 * 1024 * 1024))
|
31
|
-
metrics = db2s3.metrics
|
32
|
-
metrics.should == {
|
33
|
-
:storage_cost => 0.15, # 15c/GB-Month rounded up to nearest cent, we're only storing one backup
|
34
|
-
:transfer_cost => 3.0, # 10c/GB-Month * 30 backups
|
35
|
-
:db_size => 1024 * 1024 * 1024, # 1 GB
|
36
|
-
:total_cost => 3.17,
|
37
|
-
:requests_cost => 0.02,
|
38
|
-
:full_backups_per_month => 30 # Default 1 backup/day
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'rounds transfer cost metric up to nearest cent' do
|
43
|
-
db2s3 = DB2S3.new
|
44
|
-
# 1 KB DB
|
45
|
-
db2s3.stub!(:dump_db).and_return(stub("dump file", :size => 1024))
|
46
|
-
metrics = db2s3.metrics
|
47
|
-
metrics[:storage_cost].should == 0.01
|
48
|
-
metrics[:transfer_cost].should == 0.01
|
49
|
-
end
|
50
26
|
end
|
data/tasks/tasks.rake
CHANGED
@@ -9,32 +9,27 @@ namespace :db2s3 do
|
|
9
9
|
task :restore => :environment do
|
10
10
|
DB2S3.new.restore
|
11
11
|
end
|
12
|
-
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
desc "Show table sizes for your database"
|
14
|
+
task :statistics => :environment do
|
15
|
+
# From http://mysqlpreacher.com/wordpress/tag/table-size/
|
16
|
+
results = ActiveRecord::Base.connection.execute(<<-EOS)
|
17
|
+
SELECT
|
18
|
+
engine,
|
19
|
+
ROUND(data_length/1024/1024,2) total_size_mb,
|
20
|
+
ROUND(index_length/1024/1024,2) total_index_size_mb,
|
21
|
+
table_rows,
|
22
|
+
table_name article_attachment
|
23
|
+
FROM information_schema.tables
|
24
|
+
WHERE table_schema = 'rhnh_production'
|
25
|
+
ORDER BY 3 desc;
|
26
|
+
EOS
|
22
27
|
|
23
|
-
|
24
|
-
"
|
28
|
+
rows = []
|
29
|
+
header = [["Type", "Data MB", "Index", "Rows", "Name"], []]
|
30
|
+
results.each {|x| rows << x.to_a }
|
31
|
+
rows.sort_by {|x| -x[3].to_i }
|
32
|
+
puts (header + rows).collect {|x| x.join("\t") }
|
25
33
|
end
|
26
|
-
|
27
|
-
metrics = DB2S3.new.metrics
|
28
|
-
puts <<-EOS
|
29
|
-
Estimates only, does not take into account metadata overhead
|
30
|
-
Code has recently been added that keeps old backups around - this is not taken into account in these estimates
|
31
|
-
|
32
|
-
DB Size: #{format_size(metrics[:db_size])}
|
33
|
-
Full backups/month: #{metrics[:full_backups_per_month]}
|
34
|
-
Storage Cost $US: #{format_cost(metrics[:storage_cost])}
|
35
|
-
Transfer Cost $US: #{format_cost(metrics[:transfer_cost])}
|
36
|
-
Requests Cost $US: #{format_cost(metrics[:requests_cost])}
|
37
|
-
Total Cost $US: #{format_cost(metrics[:total_cost])}
|
38
|
-
EOS
|
39
34
|
end
|
40
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db2s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Shay
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-06 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -26,7 +26,7 @@ files:
|
|
26
26
|
- HISTORY
|
27
27
|
- README
|
28
28
|
- Rakefile
|
29
|
-
-
|
29
|
+
- VERSION
|
30
30
|
- init.rb
|
31
31
|
- lib/db2s3.rb
|
32
32
|
- lib/db2s3/tasks.rb
|
data/db2s3.gemspec
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{db2s3}
|
8
|
-
s.version = "0.2.5"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Xavier Shay"]
|
12
|
-
s.date = %q{2009-11-07}
|
13
|
-
s.description = %q{db2s3 provides rake tasks for backing up and restoring your DB to S3}
|
14
|
-
s.email = %q{contact@rhnh.net}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".gitignore",
|
20
|
-
"HISTORY",
|
21
|
-
"README",
|
22
|
-
"Rakefile",
|
23
|
-
"db2s3.gemspec",
|
24
|
-
"init.rb",
|
25
|
-
"lib/db2s3.rb",
|
26
|
-
"lib/db2s3/tasks.rb",
|
27
|
-
"rails/init.rb",
|
28
|
-
"spec/db2s3_spec.rb",
|
29
|
-
"spec/mysql_drop_schema.sql",
|
30
|
-
"spec/mysql_schema.sql",
|
31
|
-
"spec/s3_config.example.rb",
|
32
|
-
"spec/spec_helper.rb",
|
33
|
-
"tasks/tasks.rake"
|
34
|
-
]
|
35
|
-
s.homepage = %q{http://github.com/xaviershay/db2s3}
|
36
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
-
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.3.4}
|
39
|
-
s.summary = %q{Summarize your gem}
|
40
|
-
s.test_files = [
|
41
|
-
"spec/db2s3_spec.rb",
|
42
|
-
"spec/s3_config.example.rb",
|
43
|
-
"spec/spec_helper.rb"
|
44
|
-
]
|
45
|
-
|
46
|
-
if s.respond_to? :specification_version then
|
47
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
-
s.specification_version = 3
|
49
|
-
|
50
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
-
else
|
52
|
-
end
|
53
|
-
else
|
54
|
-
end
|
55
|
-
end
|