do_snapshot 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -14
- data/lib/do_snapshot/adapter.rb +3 -3
- data/lib/do_snapshot/cli.rb +2 -2
- data/lib/do_snapshot/version.rb +1 -1
- data/spec/do_snapshot/adapter/digitalocean_v2_spec.rb +0 -2
- data/spec/do_snapshot/cli_spec.rb +1 -1
- data/spec/do_snapshot/command_spec.rb +7 -8
- data/spec/do_snapshot/runner_spec.rb +3 -4
- data/spec/fixtures/digitalocean/v1/response_event.json +1 -1
- data/spec/shared/api_v2_helpers.rb +6 -6
- data/spec/shared/environment.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77cc4c07beb253d0aa7fbe1870fb45f014c6f339
|
4
|
+
data.tar.gz: 0c2acaaaddadd3626423894aaf25c8fc3a84dfb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a15514139088299e98b567a227205cc14f6d3e71b7a19707bf1ad9520690962104b57dc3f8b80bb3bae9fa515d511b082f96adfd94ab4d8909d17a846c265369
|
7
|
+
data.tar.gz: 33e4c117829a0ede9809c7930426811e8110ac9fb3d8b6ee35894e0f622535cf285205ccd263d7fd66d17ee6efc82cffeecebac2805d95e292752e8bbed0ec42
|
data/README.md
CHANGED
@@ -12,6 +12,8 @@
|
|
12
12
|
|
13
13
|
Use this tool to backup DigitalOcean droplet's via snapshot method, on the fly!
|
14
14
|
|
15
|
+
## Breaking changes: now we use DO API V2 by default, due V1 deprecation at 11.2015.
|
16
|
+
|
15
17
|
Here some features:
|
16
18
|
|
17
19
|
- Multiple threads out of the box. No matter how much droplet's you have.
|
@@ -48,7 +50,7 @@ Install it yourself as:
|
|
48
50
|
|
49
51
|
$ gem install do_snapshot
|
50
52
|
|
51
|
-
|
53
|
+
System Wide Install (OSX, *nix):
|
52
54
|
|
53
55
|
$ sudo gem install do_snapshot
|
54
56
|
|
@@ -81,6 +83,15 @@ Mainly it's pretty simple:
|
|
81
83
|
|
82
84
|
### Setup
|
83
85
|
|
86
|
+
### Digitalocean API V2 (default):
|
87
|
+
You'll need to generate an access token in Digital Ocean's control panel at https://cloud.digitalocean.com/settings/applications
|
88
|
+
|
89
|
+
$ export DIGITAL_OCEAN_ACCESS_TOKEN="SOMETOKEN"
|
90
|
+
|
91
|
+
If you want to set keys without environment, than set it via options when you run do_snapshot:
|
92
|
+
|
93
|
+
$ do_snapshot --digital-ocean-access-token YOURLONGTOKEN
|
94
|
+
|
84
95
|
### Digitalocean API V1:
|
85
96
|
You'll need to generate an access token in Digital Ocean's control panel at https://cloud.digitalocean.com/api_access
|
86
97
|
|
@@ -89,16 +100,7 @@ You'll need to generate an access token in Digital Ocean's control panel at http
|
|
89
100
|
|
90
101
|
If you want to set keys without environment, than set it via options when you run do_snapshot:
|
91
102
|
|
92
|
-
$ do_snapshot --digital-ocean-client-id YOURLONGAPICLIENTID --digital-ocean-api-key YOURLONGAPIKEY
|
93
|
-
|
94
|
-
### Digitalocean API V2:
|
95
|
-
You'll need to generate an access token in Digital Ocean's control panel at https://cloud.digitalocean.com/settings/applications
|
96
|
-
|
97
|
-
$ export DIGITAL_OCEAN_ACCESS_TOKEN="SOMETOKEN"
|
98
|
-
|
99
|
-
If you want to set keys without environment, than set it via options when you run do_snapshot:
|
100
|
-
|
101
|
-
$ do_snapshot --digital-ocean-access-token YOURLONGTOKEN
|
103
|
+
$ do_snapshot --digital-ocean-client-id YOURLONGAPICLIENTID --digital-ocean-api-key YOURLONGAPIKEY
|
102
104
|
|
103
105
|
### How-To (Here is also [Longren Tutorial](https://longren.io/automate-making-snapshots-of-your-digitalocean-droplets/))
|
104
106
|
|
@@ -106,9 +108,9 @@ Here we `keeping` only 5 **latest** snapshots and cleanup older after new one is
|
|
106
108
|
|
107
109
|
$ do_snapshot --keep 5 -c
|
108
110
|
|
109
|
-
Using API
|
111
|
+
Using API V1:
|
110
112
|
|
111
|
-
$ do_snapshot -p
|
113
|
+
$ do_snapshot -p 1
|
112
114
|
|
113
115
|
Keep latest 3 from selected droplet:
|
114
116
|
|
@@ -162,7 +164,7 @@ For working mailer you need to set e-mail settings via run options.
|
|
162
164
|
|
163
165
|
Options:
|
164
166
|
-p, [--protocol=1] # Select api version.
|
165
|
-
# Default:
|
167
|
+
# Default: 2
|
166
168
|
-o, [--only=123456 123456 123456] # Select some droplets.
|
167
169
|
-e, [--exclude=123456 123456 123456] # Except some droplets.
|
168
170
|
-k, [--keep=5] # How much snapshots you want to keep?
|
data/lib/do_snapshot/adapter.rb
CHANGED
@@ -10,10 +10,10 @@ module DoSnapshot
|
|
10
10
|
module Adapter
|
11
11
|
def api(protocol, options)
|
12
12
|
case protocol
|
13
|
-
when
|
14
|
-
return DigitaloceanV2.new(options)
|
15
|
-
else
|
13
|
+
when 1
|
16
14
|
return Digitalocean.new(options)
|
15
|
+
else
|
16
|
+
return DigitaloceanV2.new(options)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
module_function :api
|
data/lib/do_snapshot/cli.rb
CHANGED
@@ -42,7 +42,7 @@ module DoSnapshot
|
|
42
42
|
|
43
43
|
Select api version (1, 2):
|
44
44
|
|
45
|
-
$ do_snapshot -
|
45
|
+
$ do_snapshot -p 1
|
46
46
|
|
47
47
|
Set DigitalOcean keys:
|
48
48
|
|
@@ -78,7 +78,7 @@ module DoSnapshot
|
|
78
78
|
LONGDESC
|
79
79
|
method_option :protocol,
|
80
80
|
type: :numeric,
|
81
|
-
default:
|
81
|
+
default: 2,
|
82
82
|
aliases: %w( -p ),
|
83
83
|
banner: '1',
|
84
84
|
desc: 'Select api version.'
|
data/lib/do_snapshot/version.rb
CHANGED
@@ -8,12 +8,12 @@ RSpec.describe DoSnapshot::Command do
|
|
8
8
|
subject(:cmd) { DoSnapshot::Command.new }
|
9
9
|
subject(:log) { DoSnapshot::Log }
|
10
10
|
|
11
|
-
describe 'V2' do
|
12
|
-
include_context 'api_v2_helpers'
|
13
|
-
end
|
14
|
-
|
15
11
|
describe 'V1' do
|
16
12
|
include_context 'api_v1_helpers'
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'V2' do
|
16
|
+
include_context 'api_v2_helpers'
|
17
17
|
|
18
18
|
describe '.snap' do
|
19
19
|
context 'when success' do
|
@@ -215,8 +215,7 @@ RSpec.describe DoSnapshot::Command do
|
|
215
215
|
|
216
216
|
it 'with start error' do
|
217
217
|
stub_droplet_inactive(droplet_id)
|
218
|
-
|
219
|
-
stub_event_fail(event_id)
|
218
|
+
stub_droplet_start_done(droplet_id)
|
220
219
|
|
221
220
|
expect { cmd.fail_power_off(DoSnapshot::DropletShutdownError.new(droplet_id)) }
|
222
221
|
.not_to raise_error
|
@@ -234,8 +233,8 @@ RSpec.describe DoSnapshot::Command do
|
|
234
233
|
end
|
235
234
|
|
236
235
|
def load_options(options = nil)
|
237
|
-
options ||= default_options.merge(protocol:
|
238
|
-
cmd.load_options(options, [:log, :mail, :smtp, :trace, :
|
236
|
+
options ||= default_options.merge(protocol: 2)
|
237
|
+
cmd.load_options(options, [:log, :mail, :smtp, :trace, :digital_ocean_access_token])
|
239
238
|
end
|
240
239
|
|
241
240
|
def snap_runner
|
@@ -185,10 +185,6 @@ RSpec.describe DoSnapshot::Runner, type: :aruba do
|
|
185
185
|
end
|
186
186
|
|
187
187
|
context 'API V2' do
|
188
|
-
let(:default_options_cli) { default_options.reject { |key, _| %w( droplets threads ).include?(key.to_s) }.merge(protocol: 2) }
|
189
|
-
let(:event_id) { '7499' }
|
190
|
-
let(:snapshot_name) { "example.com_#{DateTime.now.strftime('%Y_%m_%d')}" }
|
191
|
-
|
192
188
|
include_context 'api_v2_helpers'
|
193
189
|
it_behaves_like '.snap methods'
|
194
190
|
|
@@ -216,6 +212,9 @@ RSpec.describe DoSnapshot::Runner, type: :aruba do
|
|
216
212
|
end
|
217
213
|
|
218
214
|
context 'API V1' do
|
215
|
+
let(:default_options_cli) { default_options.merge(protocol: 1) }
|
216
|
+
let(:snapshot_name) { "foo_#{DateTime.now.strftime('%Y_%m_%d')}" }
|
217
|
+
|
219
218
|
include_context 'api_v1_helpers'
|
220
219
|
it_behaves_like '.snap methods'
|
221
220
|
|
@@ -50,7 +50,6 @@ shared_context 'api_v2_helpers' do
|
|
50
50
|
def stub_droplet_stop(id)
|
51
51
|
stub_with_id(droplet_stop_uri, id, 'v2/show_event_power_off_start', :post,
|
52
52
|
type: 'power_off'
|
53
|
-
|
54
53
|
)
|
55
54
|
end
|
56
55
|
|
@@ -66,16 +65,18 @@ shared_context 'api_v2_helpers' do
|
|
66
65
|
def stub_droplet_start(id)
|
67
66
|
stub_with_id(droplet_start_uri, id, 'v2/show_event_power_on_start', :post,
|
68
67
|
type: 'power_on'
|
68
|
+
)
|
69
|
+
end
|
69
70
|
|
71
|
+
def stub_droplet_start_done(id)
|
72
|
+
stub_with_id(droplet_start_uri, id, 'v2/show_event_power_on_done', :post,
|
73
|
+
type: 'power_on'
|
70
74
|
)
|
71
75
|
end
|
72
76
|
|
73
77
|
def stub_droplet_start_fail(id)
|
74
78
|
stub_with_id(droplet_start_uri, id, 'v2/error_message', :post,
|
75
|
-
|
76
|
-
type: 'power_on'
|
77
|
-
},
|
78
|
-
404
|
79
|
+
type: 'power_on'
|
79
80
|
)
|
80
81
|
end
|
81
82
|
|
@@ -85,7 +86,6 @@ shared_context 'api_v2_helpers' do
|
|
85
86
|
stub_with_id_name(snapshot_uri, id, name, 'v2/response_event', :post,
|
86
87
|
type: 'snapshot',
|
87
88
|
name: name
|
88
|
-
|
89
89
|
)
|
90
90
|
end
|
91
91
|
|
data/spec/shared/environment.rb
CHANGED
@@ -11,15 +11,15 @@ shared_context 'spec' do
|
|
11
11
|
let(:client_key) { 'foo' }
|
12
12
|
let(:api_key) { 'bar' }
|
13
13
|
let(:access_token) { 'sometoken' }
|
14
|
-
let(:event_id) { '
|
14
|
+
let(:event_id) { '7499' }
|
15
15
|
let(:droplet_id) { '100823' }
|
16
16
|
let(:image_id) { '5019770' }
|
17
17
|
let(:image_id2) { '5019903' }
|
18
18
|
let(:cli_env_nil) { Hash['DIGITAL_OCEAN_CLIENT_ID' => nil, 'DIGITAL_OCEAN_API_KEY' => nil, 'DIGITAL_OCEAN_ACCESS_TOKEN' => nil] }
|
19
19
|
let(:cli_keys) { Thor::CoreExt::HashWithIndifferentAccess.new(digital_ocean_client_id: client_key, digital_ocean_api_key: api_key, digital_ocean_access_token: access_token) }
|
20
20
|
let(:cli_keys_other) { Thor::CoreExt::HashWithIndifferentAccess.new(digital_ocean_client_id: 'NOTFOO', digital_ocean_api_key: 'NOTBAR', digital_ocean_access_token: 'NOTTOK') }
|
21
|
-
let(:snapshot_name) { "
|
22
|
-
let(:default_options) { Hash[protocol:
|
21
|
+
let(:snapshot_name) { "example.com_#{DateTime.now.strftime('%Y_%m_%d')}" }
|
22
|
+
let(:default_options) { Hash[protocol: 2, only: %w( 100823 ), exclude: %w(), keep: 3, stop: false, trace: true, clean: true, delay: 0, timeout: 600] }
|
23
23
|
let(:default_options_cli) { default_options.reject { |key, _| %w( droplets threads ).include?(key.to_s) } }
|
24
24
|
let(:no_exclude) { [] }
|
25
25
|
let(:exclude) { %w( 100824 100825 ) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: do_snapshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Merkulov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: digitalocean_c
|