new_backup 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rvmrc +48 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +7 -0
- data/README.md +56 -0
- data/README.rdoc +53 -0
- data/Rakefile +70 -0
- data/bin/new_backup +47 -0
- data/features/new_backup.feature +14 -0
- data/features/step_definitions/new_backup_steps.rb +1 -0
- data/features/support/env.rb +16 -0
- data/lib/new_backup.rb +10 -0
- data/lib/new_backup/datadog.rb +92 -0
- data/lib/new_backup/main.rb +193 -0
- data/lib/new_backup/myrds.rb +140 -0
- data/lib/new_backup/mys3.rb +123 -0
- data/lib/new_backup/mysqlcmds.rb +95 -0
- data/lib/new_backup/version.rb +17 -0
- data/new_backup.gemspec +27 -0
- data/sample-config.yml +20 -0
- data/spec/datadog_spec.rb +31 -0
- data/spec/main_spec.rb +77 -0
- data/spec/mockbucket.rb +83 -0
- data/spec/myrds_spec.rb +131 -0
- data/spec/mys3_spec.rb +123 -0
- data/spec/mysqlcmds_spec.rb +119 -0
- data/spec/spec_helper.rb +29 -0
- metadata +234 -0
data/spec/mys3_spec.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
= mys3_spec.rb
|
4
|
+
|
5
|
+
*Copyright*:: (C) 2013 by Novu, LLC
|
6
|
+
*Author(s)*:: Tamara Temple <tamara.temple@novu.com>
|
7
|
+
*Since*:: 2013-05-02
|
8
|
+
*License*:: GPLv3
|
9
|
+
*Version*:: 0.0.1
|
10
|
+
|
11
|
+
== Description
|
12
|
+
|
13
|
+
Testing saves to AWS S3.
|
14
|
+
|
15
|
+
=end
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
require 'fog'
|
19
|
+
require 'new_backup/mys3'
|
20
|
+
require 'mockbucket.rb'
|
21
|
+
|
22
|
+
module NewBackup
|
23
|
+
|
24
|
+
describe MyS3 do
|
25
|
+
Fog.mock!
|
26
|
+
let(:options) {{
|
27
|
+
:rds => {
|
28
|
+
:instance_id => 'tamtest',
|
29
|
+
:subnet_group => '',
|
30
|
+
:instance_type => 'db.t1.micro'
|
31
|
+
},
|
32
|
+
:aws => {
|
33
|
+
:access_key => "A Bogus Access Key",
|
34
|
+
:secret_key => "A Bogus Secret Key",
|
35
|
+
:region => 'us-east-1'
|
36
|
+
},
|
37
|
+
:s3 => {
|
38
|
+
:raw_bucket => 'raw-bucket',
|
39
|
+
:clean_bucket => 'clean-bucket',
|
40
|
+
:prefix => 'db-dumps',
|
41
|
+
:region => 'us-east-1',
|
42
|
+
:dump_ttl => 0
|
43
|
+
},
|
44
|
+
:dump_directory => '/tmp',
|
45
|
+
:timestamp => Time.now.strftime("%Y-%m-%d-%H-%M-%S-%Z")
|
46
|
+
}}
|
47
|
+
|
48
|
+
let(:s3) { NewBackup::MyS3.new(options) }
|
49
|
+
|
50
|
+
|
51
|
+
describe "#connect" do
|
52
|
+
it { s3.should respond_to(:connect) }
|
53
|
+
it "should yield a connection" do
|
54
|
+
s3.connect do |s3|
|
55
|
+
s3.should be_a(Fog::Storage::AWS::Mock)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
describe "#connect_bucket" do
|
62
|
+
it { s3.should respond_to(:connect_bucket) }
|
63
|
+
|
64
|
+
let(:connection) { MockConnection.new(3, "aws-s3") }
|
65
|
+
|
66
|
+
it "should connect to a bucket and yield a block" do
|
67
|
+
connection.directories.create(options[:s3][:raw_bucket])
|
68
|
+
s3.connect_bucket(connection, options[:s3][:raw_bucket]) do |bucket|
|
69
|
+
bucket.key.should == options[:s3][:raw_bucket]
|
70
|
+
bucket.should respond_to(:files)
|
71
|
+
bucket.should respond_to(:create)
|
72
|
+
bucket.should respond_to(:all)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
describe "save file" do
|
82
|
+
let(:lorem) {"/tmp/loremipsum.txt"}
|
83
|
+
let(:bucket_name) {options[:s3][:raw_bucket]}
|
84
|
+
let(:s3_name) {"s3://"+File.join(bucket_name, options[:s3][:prefix], File.basename(lorem))}
|
85
|
+
before do
|
86
|
+
FileUtils.touch(lorem)
|
87
|
+
end
|
88
|
+
|
89
|
+
it { s3.should respond_to(:put_file) }
|
90
|
+
|
91
|
+
it "should save a file" do
|
92
|
+
bucket = MockBucket.new(3, bucket_name)
|
93
|
+
s3.put_file(bucket, lorem).should == s3_name
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "prune files" do
|
99
|
+
|
100
|
+
let(:bucket) { MockBucket.new(10, options[:s3][:raw_bucket]) }
|
101
|
+
|
102
|
+
it {s3.should respond_to(:prune)}
|
103
|
+
|
104
|
+
it "should not remove any files" do
|
105
|
+
s3.prune(bucket, 0).should == bucket.files.all.count
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should keep one file" do
|
109
|
+
s3.prune(bucket, 1).should == 1
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
= mysqlcmds_spec.rb
|
4
|
+
|
5
|
+
*Copyright*:: (C) 2013 by Novu, LLC
|
6
|
+
*Author(s)*:: Tamara Temple <tamara.temple@novu.com>
|
7
|
+
*Since*:: 2013-05-01
|
8
|
+
*License*:: GPLv3
|
9
|
+
*Version*:: 0.0.1
|
10
|
+
|
11
|
+
== Description
|
12
|
+
|
13
|
+
Test the class NewBackup::MySqlCmds
|
14
|
+
|
15
|
+
=end
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
require 'new_backup/mysqlcmds.rb'
|
19
|
+
require 'RunIt'
|
20
|
+
|
21
|
+
module NewBackup
|
22
|
+
|
23
|
+
describe MySqlCmds do
|
24
|
+
|
25
|
+
let(:dbhost) {"localhost"}
|
26
|
+
let(:dbuser) {"root"}
|
27
|
+
let(:dbname) {"backuptest"}
|
28
|
+
let(:dump_file) {"tmp/spec_dump_test.sql.gz"}
|
29
|
+
let(:local_obfuscate_script) {"tmp/spec_obfuscate_spec_script.sql"}
|
30
|
+
let(:createdb_sql) {"tmp/spec_createdb.sql"}
|
31
|
+
|
32
|
+
describe "verify methods" do
|
33
|
+
it { NewBackup::MySqlCmds.should respond_to(:new) }
|
34
|
+
it { NewBackup::MySqlCmds.new(dbhost, dbuser, '', dbname, local_obfuscate_script).should respond_to(:dump) }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#initialize" do
|
38
|
+
let(:mysql) {NewBackup::MySqlCmds.new(dbhost, dbuser, '', dbname, local_obfuscate_script)}
|
39
|
+
|
40
|
+
context "initializes correctly" do
|
41
|
+
it {mysql.should be_a(NewBackup::MySqlCmds)}
|
42
|
+
it {mysql.instance_variables.should include :@hostname}
|
43
|
+
it {mysql.instance_variables.should include :@username}
|
44
|
+
it {mysql.instance_variables.should include :@password}
|
45
|
+
it {mysql.instance_variables.should include :@database}
|
46
|
+
it {mysql.instance_variables.should include :@obfuscate_script}
|
47
|
+
it {mysql.instance_variables.should include :@commands}
|
48
|
+
end
|
49
|
+
|
50
|
+
context "gets useful commands" do
|
51
|
+
|
52
|
+
let(:commands) {mysql.instance_variable_get(:@commands)}
|
53
|
+
|
54
|
+
it {commands.should include :mysqldump}
|
55
|
+
it {commands.should include :mysql}
|
56
|
+
it {commands.should include :gzip}
|
57
|
+
it {commands[:mysqldump].should include "mysqldump"}
|
58
|
+
it {commands[:mysql].should include "mysql"}
|
59
|
+
it {commands[:gzip].should include "gzip"}
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "actions" do
|
65
|
+
|
66
|
+
|
67
|
+
before do
|
68
|
+
|
69
|
+
File.open(createdb_sql,'w') do |createdb|
|
70
|
+
createdb.puts <<-EOF
|
71
|
+
create table posts (
|
72
|
+
id int not null auto_increment, primary key (id),
|
73
|
+
title varchar(255),
|
74
|
+
body text
|
75
|
+
);
|
76
|
+
|
77
|
+
insert into posts (title, body) values ("Post One", "this is post one");
|
78
|
+
insert into posts (title, body) values ("Post Two", "this is post two");
|
79
|
+
select * from posts;
|
80
|
+
EOF
|
81
|
+
end # creating createdb.sql
|
82
|
+
|
83
|
+
|
84
|
+
File.open(local_obfuscate_script,'w') do |obfscript|
|
85
|
+
obfscript.puts <<-EOF
|
86
|
+
update posts set body = "this has been obfuscated";
|
87
|
+
select * from posts;
|
88
|
+
EOF
|
89
|
+
end
|
90
|
+
|
91
|
+
`mysqladmin --force --host #{dbhost} --user #{dbuser} drop #{dbname}`
|
92
|
+
`mysqladmin --force --host #{dbhost} --user #{dbuser} create #{dbname}`
|
93
|
+
`mysql --host #{dbhost} --user #{dbuser} #{dbname} < #{createdb_sql}`
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
let(:mysql) {NewBackup::MySqlCmds.new('localhost', 'root', '', 'backuptest', local_obfuscate_script) }
|
99
|
+
|
100
|
+
|
101
|
+
describe "#dump command" do
|
102
|
+
it "should perform the dump" do
|
103
|
+
File.unlink(dump_file) if File.exists?(dump_file)
|
104
|
+
mysql.dump(dump_file)
|
105
|
+
File.exists?(dump_file).should be_true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#obfuscate command" do
|
110
|
+
it "should run the obfuscate script" do
|
111
|
+
mysql.obfuscate
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
#config.order = 'random'
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
require 'methadone'
|
21
|
+
|
22
|
+
module NewBackup
|
23
|
+
|
24
|
+
class Dummy
|
25
|
+
include Methadone::CLILogging
|
26
|
+
logger.level = Logger::DEBUG
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: new_backup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tamara Temple
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rdoc
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: aruba
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.9.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: methadone
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.2.6
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.2.6
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: RunIt
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: fog
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: dogapi
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: debugger
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
description: Backup an RDS database instance to S3, and create and obfuscated version
|
159
|
+
email:
|
160
|
+
- tamouse@gmail.com
|
161
|
+
executables:
|
162
|
+
- new_backup
|
163
|
+
extensions: []
|
164
|
+
extra_rdoc_files: []
|
165
|
+
files:
|
166
|
+
- .gitignore
|
167
|
+
- .rvmrc
|
168
|
+
- Gemfile
|
169
|
+
- Gemfile.lock
|
170
|
+
- LICENSE.txt
|
171
|
+
- README.md
|
172
|
+
- README.rdoc
|
173
|
+
- Rakefile
|
174
|
+
- bin/new_backup
|
175
|
+
- features/new_backup.feature
|
176
|
+
- features/step_definitions/new_backup_steps.rb
|
177
|
+
- features/support/env.rb
|
178
|
+
- lib/new_backup.rb
|
179
|
+
- lib/new_backup/datadog.rb
|
180
|
+
- lib/new_backup/main.rb
|
181
|
+
- lib/new_backup/myrds.rb
|
182
|
+
- lib/new_backup/mys3.rb
|
183
|
+
- lib/new_backup/mysqlcmds.rb
|
184
|
+
- lib/new_backup/version.rb
|
185
|
+
- new_backup.gemspec
|
186
|
+
- sample-config.yml
|
187
|
+
- spec/datadog_spec.rb
|
188
|
+
- spec/main_spec.rb
|
189
|
+
- spec/mockbucket.rb
|
190
|
+
- spec/myrds_spec.rb
|
191
|
+
- spec/mys3_spec.rb
|
192
|
+
- spec/mysqlcmds_spec.rb
|
193
|
+
- spec/spec_helper.rb
|
194
|
+
homepage: ''
|
195
|
+
licenses: []
|
196
|
+
post_install_message:
|
197
|
+
rdoc_options: []
|
198
|
+
require_paths:
|
199
|
+
- lib
|
200
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ! '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
206
|
+
segments:
|
207
|
+
- 0
|
208
|
+
hash: 1565671872662053350
|
209
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
|
+
none: false
|
211
|
+
requirements:
|
212
|
+
- - ! '>='
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '0'
|
215
|
+
segments:
|
216
|
+
- 0
|
217
|
+
hash: 1565671872662053350
|
218
|
+
requirements: []
|
219
|
+
rubyforge_project:
|
220
|
+
rubygems_version: 1.8.24
|
221
|
+
signing_key:
|
222
|
+
specification_version: 3
|
223
|
+
summary: Backup an RDS database instance to S3, and create and obfuscated version
|
224
|
+
test_files:
|
225
|
+
- features/new_backup.feature
|
226
|
+
- features/step_definitions/new_backup_steps.rb
|
227
|
+
- features/support/env.rb
|
228
|
+
- spec/datadog_spec.rb
|
229
|
+
- spec/main_spec.rb
|
230
|
+
- spec/mockbucket.rb
|
231
|
+
- spec/myrds_spec.rb
|
232
|
+
- spec/mys3_spec.rb
|
233
|
+
- spec/mysqlcmds_spec.rb
|
234
|
+
- spec/spec_helper.rb
|