xaviershay-db2s3 0.2.2 → 0.2.5

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 CHANGED
@@ -31,7 +31,7 @@ Usage:
31
31
  rake db2s3:backup:restore # You should be testing this regularly
32
32
 
33
33
  Caveats:
34
- Currently only stores the latest backup
34
+ Currently does not clean up old back ups
35
35
 
36
36
  Kudos:
37
37
  http://github.com/pauldowman/blog_code_examples/tree/master/mysql_s3_backup
data/db2s3.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{db2s3}
5
- s.version = "0.2.2"
5
+ s.version = "0.2.5"
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"]
9
- s.date = %q{2009-03-08}
9
+ s.date = %q{2009-09-22}
10
10
  s.description = %q{db2s3 provides rake tasks for backing up and restoring your DB to S3}
11
11
  s.email = %q{contact@rhnh.net}
12
12
  s.files = %w(
@@ -24,7 +24,6 @@ Gem::Specification.new do |s|
24
24
  spec/mysql_drop_schema.sql
25
25
  spec/mysql_schema.sql
26
26
  spec/s3_config.example.rb
27
- spec/s3_config.rb
28
27
  spec/spec_helper.rb
29
28
  tasks
30
29
  tasks/tasks.rake
data/lib/db2s3.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'aws/s3'
2
+ require 'tempfile'
2
3
 
3
4
  class DB2S3
4
5
  class Config
@@ -8,11 +9,14 @@ class DB2S3
8
9
  end
9
10
 
10
11
  def full_backup
11
- store.store("dump-#{db_credentials[:database]}.sql.gz", open(dump_db.path))
12
+ file_name = "dump-#{db_credentials[:database]}-#{Time.now.utc.strftime("%Y%m%d%H%M")}.sql.gz"
13
+ store.store(file_name, open(dump_db.path))
14
+ store.store(most_recent_dump_file_name, file_name)
12
15
  end
13
16
 
14
17
  def restore
15
- file = store.fetch("dump-#{db_credentials[:database]}.sql.gz")
18
+ dump_file_name = store.fetch(most_recent_dump_file_name).read
19
+ file = store.fetch(dump_file_name)
16
20
  run "gunzip -c #{file.path} | mysql #{mysql_options}"
17
21
  end
18
22
 
@@ -51,8 +55,9 @@ class DB2S3
51
55
  end
52
56
 
53
57
  def mysql_options
54
- cmd = " -u#{db_credentials[:user]} "
58
+ cmd = " -u #{db_credentials[:username]} "
55
59
  cmd += " -p'#{db_credentials[:password]}'" unless db_credentials[:password].nil?
60
+ cmd += " -h '#{db_credentials[:host]}'" unless db_credentials[:host].nil?
56
61
  cmd += " #{db_credentials[:database]}"
57
62
  end
58
63
 
@@ -60,6 +65,10 @@ class DB2S3
60
65
  @store ||= S3Store.new
61
66
  end
62
67
 
68
+ def most_recent_dump_file_name
69
+ "most-recent-dump-#{db_credentials[:database]}.txt"
70
+ end
71
+
63
72
  def run(command)
64
73
  result = system(command)
65
74
  raise("error, process exited with status #{$?.exitstatus}") unless result
data/spec/db2s3_spec.rb CHANGED
@@ -12,14 +12,16 @@ describe 'db2s3' do
12
12
  class Person < ActiveRecord::Base
13
13
  end
14
14
 
15
- it 'can save and restore a backup to S3' do
16
- db2s3 = DB2S3.new
17
- load_schema
18
- Person.create!(:name => "Baxter")
19
- db2s3.full_backup
20
- drop_schema
21
- db2s3.restore
22
- Person.find_by_name("Baxter").should_not be_nil
15
+ if DB2S3::Config.const_defined?('S3')
16
+ it 'can save and restore a backup to S3' do
17
+ db2s3 = DB2S3.new
18
+ load_schema
19
+ Person.create!(:name => "Baxter")
20
+ db2s3.full_backup
21
+ drop_schema
22
+ db2s3.restore
23
+ Person.find_by_name("Baxter").should_not be_nil
24
+ end
23
25
  end
24
26
 
25
27
  it 'provides estimated metrics' do
@@ -1,7 +1,5 @@
1
- DB2S3::Config.instance_eval do
2
- S3 = {
3
- :access_key_id => 'yourkey',
4
- :secret_access_key => 'yoursecretkey',
5
- :bucket => 'db2s3_test'
6
- }
7
- end
1
+ DB2S3::Config:: S3 = {
2
+ :access_key_id => 'yourkey',
3
+ :secret_access_key => 'yoursecretkey',
4
+ :bucket => 'db2s3_test'
5
+ }
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  require 'spec'
2
2
  require 'activerecord'
3
3
  require File.dirname(__FILE__) + '/../lib/db2s3'
4
- require File.dirname(__FILE__) + '/s3_config.rb'
4
+ if File.exists?(File.dirname(__FILE__) + '/s3_config.rb')
5
+ require File.dirname(__FILE__) + '/s3_config.rb'
6
+ else
7
+ puts "s3_config.rb does not exist - not running live tests"
8
+ end
5
9
 
6
10
  DBConfig = {
7
11
  :adapter => "mysql",
data/tasks/tasks.rake CHANGED
@@ -27,6 +27,7 @@ namespace :db2s3 do
27
27
  metrics = DB2S3.new.metrics
28
28
  puts <<-EOS
29
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
30
31
 
31
32
  DB Size: #{format_size(metrics[:db_size])}
32
33
  Full backups/month: #{metrics[:full_backups_per_month]}
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: 0.2.2
4
+ version: 0.2.5
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-03-08 00:00:00 -08:00
12
+ date: 2009-09-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,12 +45,12 @@ files:
45
45
  - spec/mysql_drop_schema.sql
46
46
  - spec/mysql_schema.sql
47
47
  - spec/s3_config.example.rb
48
- - spec/s3_config.rb
49
48
  - spec/spec_helper.rb
50
49
  - tasks
51
50
  - tasks/tasks.rake
52
51
  has_rdoc: false
53
52
  homepage: http://github.com/xaviershay/db2s3
53
+ licenses:
54
54
  post_install_message:
55
55
  rdoc_options: []
56
56
 
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements: []
72
72
 
73
73
  rubyforge_project:
74
- rubygems_version: 1.2.0
74
+ rubygems_version: 1.3.5
75
75
  signing_key:
76
76
  specification_version: 2
77
77
  summary: db2s3 provides rake tasks for backing up and restoring your DB to S3