stratocumulus 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/lib/stratocumulus/database.rb +6 -0
- data/lib/stratocumulus/database/etcd.rb +44 -0
- data/lib/stratocumulus/database/mysql.rb +1 -0
- data/lib/stratocumulus/runner.rb +8 -2
- data/lib/stratocumulus/version.rb +1 -1
- data/spec/unit/etcd_spec.rb +59 -0
- data/spec/unit/mysql_spec.rb +6 -6
- data/spec/unit/runner_spec.rb +47 -4
- metadata +6 -4
- data/.rubocop.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f977577efc1b17518ff6bb4c33e5d21fa99055f8
|
4
|
+
data.tar.gz: 4c802f4f3a257a2d084d0a6a862f2fc0532d027f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a18a403c0bb9d85621ae87457e700adf057afeaae3bd80b4f9e5815efaf588ea6137e57b4cdc15d1789686784f20b1d928a38aeb471233e93473d6acadeb799e
|
7
|
+
data.tar.gz: 893881db830455f0bce0d563faa1775a2887ebb929c5a4c24ee59d9fc7344c05c72d1f8d0a81200adb2d14e2d2e32f031179a32f8b340beb559312ad6e5434ea
|
data/.travis.yml
CHANGED
@@ -5,6 +5,10 @@ rvm:
|
|
5
5
|
- 2.1.8
|
6
6
|
env: CODECLIMATE_REPO_TOKEN=650676b7530bf62fce4284e263272a8dcab015f4f34fe6dab251ead2ea6b4813
|
7
7
|
sudo: false
|
8
|
+
before_install:
|
9
|
+
- curl -L https://github.com/coreos/etcd/releases/download/v2.3.0/etcd-v2.3.0-linux-amd64.tar.gz -o etcd-v2.3.0-linux-amd64.tar.gz
|
10
|
+
- tar xzvf etcd-v2.3.0-linux-amd64.tar.gz
|
11
|
+
- export PATH=$PWD/etcd-v2.3.0-linux-amd64:$PATH
|
8
12
|
services:
|
9
13
|
- mysql
|
10
14
|
- postgresql
|
@@ -2,6 +2,7 @@
|
|
2
2
|
require "stratocumulus/database/pipe_io"
|
3
3
|
require "stratocumulus/database/mysql"
|
4
4
|
require "stratocumulus/database/postgresql"
|
5
|
+
require "stratocumulus/database/etcd"
|
5
6
|
require "English"
|
6
7
|
|
7
8
|
module Stratocumulus
|
@@ -16,6 +17,7 @@ module Stratocumulus
|
|
16
17
|
{
|
17
18
|
"psql" => PostgreSQL,
|
18
19
|
"mysql" => MySQL,
|
20
|
+
"etcd" => ETCD,
|
19
21
|
}
|
20
22
|
end
|
21
23
|
|
@@ -47,6 +49,10 @@ module Stratocumulus
|
|
47
49
|
["gzip"]
|
48
50
|
end
|
49
51
|
|
52
|
+
def cleanup
|
53
|
+
# NOOP
|
54
|
+
end
|
55
|
+
|
50
56
|
private
|
51
57
|
|
52
58
|
def check_dependencies
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require "stratocumulus/database"
|
3
|
+
require "tmpdir"
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
module Stratocumulus
|
7
|
+
class ETCD < Database
|
8
|
+
def initialize(options = {})
|
9
|
+
@data_dir = options["data_dir"]
|
10
|
+
super(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def command
|
14
|
+
command = "etcdctl "
|
15
|
+
command << "backup "
|
16
|
+
command << "--data-dir #{data_dir} "
|
17
|
+
command << "--backup-dir #{backup_dir} "
|
18
|
+
command << "&& tar -cf - -C #{backup_dir} . "
|
19
|
+
end
|
20
|
+
|
21
|
+
def dependencies
|
22
|
+
super + %w(etcdctl tar)
|
23
|
+
end
|
24
|
+
|
25
|
+
def cleanup
|
26
|
+
FileUtils.rm_rf(backup_dir)
|
27
|
+
@_backup_dir = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def suffix
|
33
|
+
".tar.gz"
|
34
|
+
end
|
35
|
+
|
36
|
+
def data_dir
|
37
|
+
@data_dir || "/var/lib/etcd"
|
38
|
+
end
|
39
|
+
|
40
|
+
def backup_dir
|
41
|
+
@_backup_dir ||= Dir.tmpdir
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/stratocumulus/runner.rb
CHANGED
@@ -8,8 +8,14 @@ module Stratocumulus
|
|
8
8
|
|
9
9
|
def run
|
10
10
|
@config["databases"].each do |database_config|
|
11
|
-
|
12
|
-
|
11
|
+
begin
|
12
|
+
database = Database.build(database_config)
|
13
|
+
upload(database, database_config["storage"])
|
14
|
+
rescue => e
|
15
|
+
$stderr.puts "warning: #{e.message}"
|
16
|
+
ensure
|
17
|
+
database.cleanup
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe Stratocumulus::ETCD do
|
5
|
+
subject do
|
6
|
+
described_class.new(config)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:config) do
|
10
|
+
{ "name" => "etcd_test" }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#dependencies" do
|
14
|
+
specify do
|
15
|
+
expect(subject.dependencies).to eq %w(gzip etcdctl tar)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#command" do
|
20
|
+
context "default" do
|
21
|
+
it "generates the dump command with sensible defaults" do
|
22
|
+
match = %r{etcdctl backup --data-dir /var/lib/etcd --backup-dir (.*) && tar -cf - -C (.*) \.}
|
23
|
+
.match(subject.command)
|
24
|
+
# We expect the backup dir passed to etcd to be the same as the one we pass to tar
|
25
|
+
expect(match).to be_truthy
|
26
|
+
expect(match[1]).to eq(match[2])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when the datadir is set" do
|
31
|
+
let(:config) do
|
32
|
+
{
|
33
|
+
"data_dir" => "/bar/foo/etcd",
|
34
|
+
"name" => "etcd_test",
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
it "uses the given data dir" do
|
39
|
+
expect(subject.command).to include "/bar/foo/etcd"
|
40
|
+
expect(subject.command).to_not include "/var/lib/etcd"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "filename" do
|
46
|
+
it "uses the correct suffix" do
|
47
|
+
expect(subject.filename).to match(/.*\.tar\.gz$/)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#cleanup" do
|
52
|
+
it "removes the backup dir" do
|
53
|
+
match = %r{etcdctl backup --data-dir /var/lib/etcd --backup-dir (.*) && tar -cf - -C (.*) \.}
|
54
|
+
.match(subject.command)
|
55
|
+
expect(FileUtils).to receive(:rm_rf).with(match[1])
|
56
|
+
subject.cleanup
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/unit/mysql_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe Stratocumulus::MySQL do
|
|
20
20
|
context "default" do
|
21
21
|
it "generates the dump command with sensible defaults" do
|
22
22
|
expect(subject.command).to eq(
|
23
|
-
"mysqldump --single-transaction -uroot stratocumulus_test",
|
23
|
+
"mysqldump --single-transaction --quick -uroot stratocumulus_test",
|
24
24
|
)
|
25
25
|
end
|
26
26
|
end
|
@@ -35,7 +35,7 @@ describe Stratocumulus::MySQL do
|
|
35
35
|
|
36
36
|
it "generates the dump command with a default host" do
|
37
37
|
expect(subject.command).to eq(
|
38
|
-
"mysqldump --single-transaction -uroot -pseecrit stratocumulus_test",
|
38
|
+
"mysqldump --single-transaction --quick -uroot -pseecrit stratocumulus_test",
|
39
39
|
)
|
40
40
|
end
|
41
41
|
end
|
@@ -50,7 +50,7 @@ describe Stratocumulus::MySQL do
|
|
50
50
|
|
51
51
|
it "generates the dump command with a default host" do
|
52
52
|
expect(subject.command).to eq(
|
53
|
-
"mysqldump --single-transaction -uroot -hlocalhost -P13306 stratocumulus_test" # rubocop:disable Metrics/LineLength
|
53
|
+
"mysqldump --single-transaction --quick -uroot -hlocalhost -P13306 stratocumulus_test" # rubocop:disable Metrics/LineLength
|
54
54
|
)
|
55
55
|
end
|
56
56
|
end
|
@@ -65,7 +65,7 @@ describe Stratocumulus::MySQL do
|
|
65
65
|
|
66
66
|
it "generates the dump command with a default port" do
|
67
67
|
expect(subject.command).to eq(
|
68
|
-
"mysqldump --single-transaction -uroot -hdb.example.com -P3306 stratocumulus_test" # rubocop:disable Metrics/LineLength
|
68
|
+
"mysqldump --single-transaction --quick -uroot -hdb.example.com -P3306 stratocumulus_test" # rubocop:disable Metrics/LineLength
|
69
69
|
)
|
70
70
|
end
|
71
71
|
end
|
@@ -81,7 +81,7 @@ describe Stratocumulus::MySQL do
|
|
81
81
|
|
82
82
|
it "generates the dump command with the port and host" do
|
83
83
|
expect(subject.command).to eq(
|
84
|
-
"mysqldump --single-transaction -uroot -hdb.example.com -P33306 stratocumulus_test" # rubocop:disable Metrics/LineLength
|
84
|
+
"mysqldump --single-transaction --quick -uroot -hdb.example.com -P33306 stratocumulus_test" # rubocop:disable Metrics/LineLength
|
85
85
|
)
|
86
86
|
end
|
87
87
|
end
|
@@ -96,7 +96,7 @@ describe Stratocumulus::MySQL do
|
|
96
96
|
|
97
97
|
it "generates the dump command with the username" do
|
98
98
|
expect(subject.command).to eq(
|
99
|
-
"mysqldump --single-transaction -ususan stratocumulus_test",
|
99
|
+
"mysqldump --single-transaction --quick -ususan stratocumulus_test",
|
100
100
|
)
|
101
101
|
end
|
102
102
|
end
|
data/spec/unit/runner_spec.rb
CHANGED
@@ -4,8 +4,8 @@ require "spec_helper"
|
|
4
4
|
describe Stratocumulus::Runner do
|
5
5
|
subject { described_class.new("spec/support/test_config_file.yml") }
|
6
6
|
let(:storage) { double(upload: true) }
|
7
|
-
let(:database) { double }
|
8
|
-
let(:database2) { double }
|
7
|
+
let(:database) { double(cleanup: nil) }
|
8
|
+
let(:database2) { double(cleanup: nil) }
|
9
9
|
|
10
10
|
before do
|
11
11
|
allow(Stratocumulus::Storage).to receive(:new).and_return(storage)
|
@@ -34,13 +34,13 @@ describe Stratocumulus::Runner do
|
|
34
34
|
"password" => "sekret",
|
35
35
|
"host" => "db1.example.com",
|
36
36
|
"port" => 3307,
|
37
|
-
)
|
37
|
+
).and_return(database)
|
38
38
|
|
39
39
|
expect(Stratocumulus::Database).to receive(:new).once.with(
|
40
40
|
"type" => "mysql",
|
41
41
|
"name" => "stratocumulus_test_2",
|
42
42
|
"storage" => "s3",
|
43
|
-
)
|
43
|
+
).and_return(database2)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "uploads each database to storage" do
|
@@ -55,4 +55,47 @@ describe Stratocumulus::Runner do
|
|
55
55
|
expect(storage).to receive(:upload).once.with(database)
|
56
56
|
expect(storage).to receive(:upload).once.with(database2)
|
57
57
|
end
|
58
|
+
|
59
|
+
it "calls cleanup on the database after each upload" do
|
60
|
+
allow(Stratocumulus::Database).to receive(:new).once.with(
|
61
|
+
hash_including("name" => "stratocumulus_test"),
|
62
|
+
).and_return(database)
|
63
|
+
|
64
|
+
allow(Stratocumulus::Database).to receive(:new).once.with(
|
65
|
+
hash_including("name" => "stratocumulus_test_2"),
|
66
|
+
).and_return(database2)
|
67
|
+
|
68
|
+
|
69
|
+
expect(database).to receive(:cleanup)
|
70
|
+
expect(database2).to receive(:cleanup)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "calls cleanup on the database after each upload" do
|
74
|
+
allow(Stratocumulus::Database).to receive(:new).once.with(
|
75
|
+
hash_including("name" => "stratocumulus_test"),
|
76
|
+
).and_return(database)
|
77
|
+
|
78
|
+
allow(Stratocumulus::Database).to receive(:new).once.with(
|
79
|
+
hash_including("name" => "stratocumulus_test_2"),
|
80
|
+
).and_return(database2)
|
81
|
+
|
82
|
+
|
83
|
+
expect(database).to receive(:cleanup)
|
84
|
+
expect(database2).to receive(:cleanup)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "calls cleanup even if there was an error" do
|
88
|
+
allow(Stratocumulus::Database).to receive(:new).once.with(
|
89
|
+
hash_including("name" => "stratocumulus_test"),
|
90
|
+
).and_return(database)
|
91
|
+
|
92
|
+
allow(Stratocumulus::Database).to receive(:new).once.with(
|
93
|
+
hash_including("name" => "stratocumulus_test_2"),
|
94
|
+
).and_return(database2)
|
95
|
+
|
96
|
+
allow(storage).to receive(:upload).and_raise "Storage Is Broken Sorry"
|
97
|
+
|
98
|
+
expect(database).to receive(:cleanup)
|
99
|
+
expect(database2).to receive(:cleanup)
|
100
|
+
end
|
58
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stratocumulus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ed Robinson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-aws
|
@@ -132,7 +132,6 @@ extra_rdoc_files: []
|
|
132
132
|
files:
|
133
133
|
- ".gitignore"
|
134
134
|
- ".rspec"
|
135
|
-
- ".rubocop.yml"
|
136
135
|
- ".travis.yml"
|
137
136
|
- Gemfile
|
138
137
|
- LICENSE.txt
|
@@ -142,6 +141,7 @@ files:
|
|
142
141
|
- lib/stratocumulus.rb
|
143
142
|
- lib/stratocumulus/cli.rb
|
144
143
|
- lib/stratocumulus/database.rb
|
144
|
+
- lib/stratocumulus/database/etcd.rb
|
145
145
|
- lib/stratocumulus/database/mysql.rb
|
146
146
|
- lib/stratocumulus/database/pipe_io.rb
|
147
147
|
- lib/stratocumulus/database/postgresql.rb
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- spec/support/test_config_file.yml
|
158
158
|
- spec/unit/cli_spec.rb
|
159
159
|
- spec/unit/database_spec.rb
|
160
|
+
- spec/unit/etcd_spec.rb
|
160
161
|
- spec/unit/mysql_spec.rb
|
161
162
|
- spec/unit/pipe_io_spec.rb
|
162
163
|
- spec/unit/postgresql_spec.rb
|
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
185
|
version: '0'
|
185
186
|
requirements: []
|
186
187
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.
|
188
|
+
rubygems_version: 2.5.1
|
188
189
|
signing_key:
|
189
190
|
specification_version: 4
|
190
191
|
summary: Backup Databases to Cloud Storage
|
@@ -197,6 +198,7 @@ test_files:
|
|
197
198
|
- spec/support/test_config_file.yml
|
198
199
|
- spec/unit/cli_spec.rb
|
199
200
|
- spec/unit/database_spec.rb
|
201
|
+
- spec/unit/etcd_spec.rb
|
200
202
|
- spec/unit/mysql_spec.rb
|
201
203
|
- spec/unit/pipe_io_spec.rb
|
202
204
|
- spec/unit/postgresql_spec.rb
|