fallout 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/LICENSE +21 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/bin/fallout +71 -0
- data/fallout.gemspec +25 -0
- data/lib/fallout/backup.rb +37 -0
- data/lib/fallout/restore.rb +10 -0
- data/lib/fallout/version.rb +3 -0
- data/lib/fallout.rb +3 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 58b93407bb2b48ce39c73c4dbcc3bc770260b32e
|
4
|
+
data.tar.gz: d3bf1ff41fe648c677518404783c13bb1dd30bfe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57ac6f64c67dc9db392c8ea2922eee7025ac906cd024c86c654072fe888cf002e4ea97efc28b4404ff07f5ce5947db2e687903a957d0f6dda31047bd5c0f8015
|
7
|
+
data.tar.gz: 23c065ae1393c703e1e6fd9e37a84f0d77ddd41d5bd758ef5ac80672925c824f186f31e93e8cc83cc45652cc9cd999465aeb63364e1fdde7782ccd22a464d5c4
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fallout (0.0.1)
|
5
|
+
aws-sdk
|
6
|
+
trollop
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
aws-sdk (1.52.0)
|
12
|
+
aws-sdk-v1 (= 1.52.0)
|
13
|
+
aws-sdk-v1 (1.52.0)
|
14
|
+
json (~> 1.4)
|
15
|
+
nokogiri (>= 1.4.4)
|
16
|
+
json (1.8.1)
|
17
|
+
mini_portile (0.6.0)
|
18
|
+
nokogiri (1.6.3.1)
|
19
|
+
mini_portile (= 0.6.0)
|
20
|
+
rake (10.3.2)
|
21
|
+
trollop (2.0)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
bundler (~> 1.5)
|
28
|
+
fallout!
|
29
|
+
rake
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Valentin Vasilyev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Fallout
|
2
|
+
|
3
|
+
Really easy Amazon EC2 backup/restore solution.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
$ gem install fallout
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
This gem installs `fallout` executable. Don't forget to run `rbenv`
|
13
|
+
rehash, if you're on rbenv.
|
14
|
+
You must have `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
|
15
|
+
environment variables set to authenticate with EC2.
|
16
|
+
|
17
|
+
Fallout supports 2 commands:
|
18
|
+
|
19
|
+
### backup
|
20
|
+
|
21
|
+
Syntax:
|
22
|
+
|
23
|
+
`fallout backup -v <volume_id> -k <keep_days>`
|
24
|
+
|
25
|
+
Example:
|
26
|
+
|
27
|
+
```
|
28
|
+
$ fallout backup -v vol-23ab3d -k 7
|
29
|
+
|
30
|
+
Deleted snapshots snap-6695b3a5, snap-ca6a3069
|
31
|
+
Created new snapshot snap-b67f7725, expires after 2014-09-14
|
32
|
+
```
|
33
|
+
|
34
|
+
_This will create a snapshot for the specified volume and will mark it
|
35
|
+
as valid for 7 days. It will also delete all expired snapshots, created for the
|
36
|
+
specified volume._
|
37
|
+
|
38
|
+
#### How does expiration work?
|
39
|
+
|
40
|
+
When creating a snapshot, `fallout` will tag it with a special
|
41
|
+
`expires_after` tag. When running the backup, `fallout` will search for
|
42
|
+
any expired snapshots and remove them. This way you can have `fallout`
|
43
|
+
running every day, it will keep N most fresh snapshots automatically.
|
44
|
+
|
45
|
+
### restore
|
46
|
+
|
47
|
+
Work in progress
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( http://github.com/<my-github-username>/fallout/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/fallout
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fallout'
|
4
|
+
require 'trollop'
|
5
|
+
|
6
|
+
cmd = ARGV.shift
|
7
|
+
help = <<-EOS
|
8
|
+
|
9
|
+
Fallout - Amazon EC2 backup and restore utility, version: #{Fallout::VERSION}
|
10
|
+
|
11
|
+
To backup:
|
12
|
+
fallout backup -v <volume_id> -k <keep_days>
|
13
|
+
|
14
|
+
options:
|
15
|
+
-v volume id to create snapshot for
|
16
|
+
-k number of days to keep the snapshots
|
17
|
+
|
18
|
+
example:
|
19
|
+
# backup volume and keep it for 3 days
|
20
|
+
fallout backup -v v23dbade3 -k 3
|
21
|
+
|
22
|
+
To restore:
|
23
|
+
fallout restore -i <instance_id> -v <volume_id>
|
24
|
+
|
25
|
+
options:
|
26
|
+
-i instance id to restore
|
27
|
+
-v volume id to restore
|
28
|
+
|
29
|
+
example:
|
30
|
+
# restore volume
|
31
|
+
fallout restore -i i39dabd -v v23dbade3
|
32
|
+
|
33
|
+
EOS
|
34
|
+
|
35
|
+
opts = case cmd
|
36
|
+
when 'backup'
|
37
|
+
Trollop::options do
|
38
|
+
opt :volume, 'Volume ID', type: :string
|
39
|
+
opt :keep, 'Number of days to keep snapshots for', type: :integer
|
40
|
+
end
|
41
|
+
when 'restore'
|
42
|
+
Trollop::options do
|
43
|
+
opt :instance, 'Instance ID', type: :string
|
44
|
+
opt :volume, 'Volume ID', type: :string
|
45
|
+
end
|
46
|
+
else
|
47
|
+
puts help
|
48
|
+
end
|
49
|
+
|
50
|
+
case cmd
|
51
|
+
when 'backup'
|
52
|
+
if(opts[:volume].nil? || opts[:keep].nil?)
|
53
|
+
puts '-v and -k are required for backup'
|
54
|
+
else
|
55
|
+
f = Fallout::Backup.new(opts)
|
56
|
+
expired_snapshots = f.delete_expired_snapshots
|
57
|
+
if expired_snapshots.any?
|
58
|
+
puts "Deleted snapshots #{expired_snapshots.map(&:id).join(', ')}"
|
59
|
+
else
|
60
|
+
puts "No expired snapshots found"
|
61
|
+
end
|
62
|
+
new_snapshot, expires_after = f.run
|
63
|
+
puts "Created new snapshot #{new_snapshot.id}, expires after #{expires_after}"
|
64
|
+
end
|
65
|
+
when 'restore'
|
66
|
+
if(opts[:instance].nil? || opts[:volume].nil?)
|
67
|
+
puts '-i and -v are required for restore'
|
68
|
+
else
|
69
|
+
Fallout::Restore.new(opts).run
|
70
|
+
end
|
71
|
+
end
|
data/fallout.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fallout/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fallout"
|
8
|
+
spec.version = Fallout::VERSION
|
9
|
+
spec.authors = ["Valentin Vasilyev"]
|
10
|
+
spec.email = ["valentin.vasilyev@outlook.com"]
|
11
|
+
spec.summary = %q{A simple ruby script that can backup and restore Amazon EC2 instances}
|
12
|
+
spec.homepage = "https://github.com/Valve/fallout"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "aws-sdk"
|
21
|
+
spec.add_dependency "trollop"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'aws'
|
2
|
+
module Fallout
|
3
|
+
class Backup
|
4
|
+
EXPIRES_AFTER_KEY = 'expires_after'.freeze
|
5
|
+
def initialize(options)
|
6
|
+
@volume_id = options[:volume]
|
7
|
+
@keep = options[:keep].to_i
|
8
|
+
@expires_after = Date.today + @keep
|
9
|
+
@ec2 = AWS::EC2.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete_expired_snapshots
|
13
|
+
snapshots = @ec2.snapshots.filter('volume-id', @volume_id)
|
14
|
+
snapshots = snapshots.map do |ss|
|
15
|
+
begin
|
16
|
+
da = Date.parse(ss.tags.to_h[EXPIRES_AFTER_KEY])
|
17
|
+
if da < Date.today
|
18
|
+
ss.delete
|
19
|
+
ss
|
20
|
+
end
|
21
|
+
rescue
|
22
|
+
next
|
23
|
+
end
|
24
|
+
end
|
25
|
+
snapshots.compact
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
@volume = @ec2.volumes[@volume_id]
|
30
|
+
raise "Volume does not exist: #{@volume_id}" if @volume.nil? || !@volume.exists?
|
31
|
+
desc = "Snapshot for volume #{@volume_id}, will be deleted after #{@expires_after}"
|
32
|
+
snapshot = @volume.create_snapshot(desc)
|
33
|
+
snapshot.add_tag(EXPIRES_AFTER_KEY, value: @expires_after.to_s)
|
34
|
+
[snapshot, @expires_after]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/fallout.rb
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fallout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Valentin Vasilyev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: trollop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- valentin.vasilyev@outlook.com
|
72
|
+
executables:
|
73
|
+
- fallout
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/fallout
|
84
|
+
- fallout.gemspec
|
85
|
+
- lib/fallout.rb
|
86
|
+
- lib/fallout/backup.rb
|
87
|
+
- lib/fallout/restore.rb
|
88
|
+
- lib/fallout/version.rb
|
89
|
+
homepage: https://github.com/Valve/fallout
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: A simple ruby script that can backup and restore Amazon EC2 instances
|
113
|
+
test_files: []
|