sdb-backup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "aws-sdk", ">= 0"
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", ">= 0"
10
+ gem "shoulda", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.4"
13
+ gem "rcov", ">= 0"
14
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 ryan-mitchell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = sdb-backup
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to sdb-backup
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 ryan-mitchell. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "sdb-backup"
18
+ gem.homepage = "http://github.com/ryan-mitchell/sdb-backup"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{SimpleDB backup tool}
21
+ gem.description = %Q{A command line tool for backing up and restoring AWS SimpleDB data. Supports various methods of backing up and restoring.}
22
+ gem.email = "rmitchell@lynchmarks.com"
23
+ gem.authors = ["ryan-mitchell"]
24
+ gem.executables = ["sdb-backup"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rdoc/task'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "sdb-backup #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sdb-backup/cli'
4
+
5
+ cli = SdbBackup::CLI.new
6
+ cli.run
@@ -0,0 +1,17 @@
1
+ class SdbBackup
2
+ module Reader
3
+
4
+ class SdbDomain
5
+
6
+ def read
7
+ puts "reading domains"
8
+ @sdb.domains
9
+ end
10
+
11
+ def initialize(sdb)
12
+ @sdb = sdb
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ require 'aws-sdk'
2
+ require 'reader/sdb_domain.rb'
3
+ require 'writer/sdb_domain.rb'
4
+
5
+ class SdbBackup
6
+
7
+ def initialize(reader, writer)
8
+ @reader = reader
9
+ @writer = writer
10
+ end
11
+
12
+ def perform
13
+ data = @reader.read
14
+ @writer.write(data)
15
+ end
16
+ end
@@ -0,0 +1,58 @@
1
+ require 'sdb-backup'
2
+ require 'optparse'
3
+
4
+ class SdbBackup
5
+
6
+ class CLI
7
+
8
+ def run
9
+
10
+ options = {}
11
+ OptionParser.new do |opts|
12
+ opts.banner = "Usage: sdb-backup [options]"
13
+
14
+ opts.on("-f", "--from=[sdb|xml]", "Backup source") do |f|
15
+ options[:from] = f
16
+ end
17
+
18
+ opts.on("-t", "--to=[sdb|xml]", "Backup destination") do |t|
19
+ options[:to] = t end
20
+
21
+ opts.on("-c", "--config=<filename>", "YAML configuration file") do |c|
22
+ options[:config_file] = c
23
+ end
24
+
25
+ opts.on_tail("-h", "--help", "Show this message") do
26
+ puts opts
27
+ exit
28
+ end
29
+ end.parse!
30
+
31
+ puts options
32
+ puts options[:source]
33
+
34
+ config = YAML.load_file(options[:config_file])
35
+ puts config.inspect
36
+
37
+ case options[:from]
38
+ when "sdb"
39
+ reader = SdbBackup::Reader::SdbDomain.new(AWS::SimpleDB.new(config['source']['sdb']))
40
+ when "xml"
41
+ puts "Reader not supported"
42
+ exit
43
+ end
44
+
45
+ case options[:to]
46
+ when "sdb"
47
+ writer = SdbBackup::Writer::SdbDomain.new(AWS::SimpleDB.new(config['destination']['sdb']))
48
+ when "xml"
49
+ puts "Writer not supported"
50
+ exit
51
+ end
52
+
53
+ sdb_backup = SdbBackup.new(reader, writer)
54
+ sdb_backup.perform
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,24 @@
1
+ class SdbBackup
2
+ module Writer
3
+
4
+ class SdbDomain
5
+
6
+ def initialize(sdb)
7
+ @sdb = sdb
8
+ end
9
+
10
+ def write(data)
11
+
12
+ @sdb.domains.each { |domain| domain.delete! }
13
+
14
+ data.each do |domain|
15
+ @sdb.domains.create(domain.name)
16
+ domain.items.each do |item|
17
+ @sdb.domains[domain.name].items.create(item.name, item.attributes.to_h)
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe SdbBackup do
4
+
5
+ context "#initialize" do
6
+
7
+ it "requires a reader and writer" do
8
+ lambda { SdbBackup.new }.should raise_error(ArgumentError)
9
+ end
10
+
11
+ it "accepts a reader and writer" do
12
+ lambda { SdbBackup.new(
13
+ mock(SdbBackup::Reader::SdbDomain),
14
+ mock(SdbBackup::Writer::SdbDomain))
15
+ }.should_not raise_error
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'sdb-backup'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe SdbBackup::Writer::SdbDomain do
4
+
5
+ let(:domain_1) { AWS::SimpleDB::Domain.new('test-domain-1') }
6
+ let(:domain_2) { AWS::SimpleDB::Domain.new('test-domain-2') }
7
+ let(:item) { AWS::SimpleDB::Item.new(domain_1, 'test-item') }
8
+ let(:sdb) { mock(AWS::SimpleDB) }
9
+ let(:writer) { SdbBackup::Writer::SdbDomain.new(sdb) }
10
+
11
+ context "#initialize" do
12
+
13
+ it "requires an access key and secret key" do
14
+ lambda { SdbBackup::Writer::SdbDomain.new }.should raise_error(ArgumentError)
15
+ end
16
+
17
+ it "should accept an access key and secret key" do
18
+ lambda {
19
+ SdbBackup::Writer::SdbDomain.new({
20
+ :access_key_id => 'test',
21
+ :secret_access_key => 'test'
22
+ })
23
+ }.should_not raise_error
24
+ end
25
+
26
+ end
27
+
28
+ context "#write" do
29
+
30
+ it "should clear all domains in the target environment" do
31
+ domain_1.should_receive(:delete!)
32
+ domain_2.should_receive(:delete!)
33
+ sdb.should_receive(:domains).and_return([domain_1, domain_2])
34
+
35
+ writer.write([])
36
+ end
37
+
38
+ it "should create a copy of each domain in the data to write" do
39
+ mock_domain_collection = mock(AWS::SimpleDB::DomainCollection)
40
+ sdb.should_receive(:domains).any_number_of_times.and_return mock_domain_collection
41
+
42
+ # for the purposes of this test the domains have no items
43
+ domain_1.should_receive(:items).and_return []
44
+ domain_2.should_receive(:items).and_return []
45
+
46
+ mock_domain_collection.should_receive(:create).with('test-domain-1')
47
+ mock_domain_collection.should_receive(:create).with('test-domain-2')
48
+ mock_domain_collection.stub(:each)
49
+
50
+ writer.write([domain_1, domain_2])
51
+ end
52
+
53
+ it "should create a copy of each item in a domain in the data to write" do
54
+ item.stub_chain(:attributes, :to_h).and_return({ :one => 'one', :two => 'two' })
55
+ domain_1.should_receive(:items).and_return [item]
56
+
57
+ sdb.stub_chain(:domains, :create)
58
+ sdb.stub_chain(:domains, :each)
59
+
60
+ mock_item_collection = mock(AWS::SimpleDB::ItemCollection)
61
+ mock_item_collection.should_receive(:create).with('test-item', { :one => 'one', :two => 'two' })
62
+
63
+ sdb.stub_chain(:domains, :[], :items).and_return mock_item_collection
64
+
65
+ writer.write([domain_1])
66
+ end
67
+
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sdb-backup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ryan-mitchell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-28 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: aws-sdk
16
+ requirement: &21348920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *21348920
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &21348220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *21348220
36
+ - !ruby/object:Gem::Dependency
37
+ name: shoulda
38
+ requirement: &21347500 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *21347500
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &21346840 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *21346840
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &21346080 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.6.4
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *21346080
69
+ - !ruby/object:Gem::Dependency
70
+ name: rcov
71
+ requirement: &21345320 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *21345320
80
+ description: A command line tool for backing up and restoring AWS SimpleDB data. Supports
81
+ various methods of backing up and restoring.
82
+ email: rmitchell@lynchmarks.com
83
+ executables:
84
+ - sdb-backup
85
+ extensions: []
86
+ extra_rdoc_files:
87
+ - LICENSE.txt
88
+ - README.rdoc
89
+ files:
90
+ - .document
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.rdoc
94
+ - Rakefile
95
+ - VERSION
96
+ - bin/sdb-backup
97
+ - lib/reader/sdb_domain.rb
98
+ - lib/sdb-backup.rb
99
+ - lib/sdb-backup/cli.rb
100
+ - lib/writer/sdb_domain.rb
101
+ - spec/sdb-backup_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/writer/sdb_domain_spec.rb
104
+ homepage: http://github.com/ryan-mitchell/sdb-backup
105
+ licenses:
106
+ - MIT
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ segments:
118
+ - 0
119
+ hash: -1784820261889617195
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.10
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: SimpleDB backup tool
132
+ test_files: []