awstools 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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in awstools.gemspec
4
+ gemspec
5
+
6
+ # once the pull is integrated switch to main branch
7
+ # gem 'amazon-ec2'
8
+ gem 'amazon-ec2', :git => 'https://github.com/stw/amazon-ec2.git', :branch => 'add_filters_to_snapshots'
9
+ gem 'trollop'
data/LICENSE ADDED
@@ -0,0 +1,66 @@
1
+ Copyright (c) 2007-2009 Glenn Rempe
2
+
3
+ This software is distributed under the Ruby License. A copy of which is
4
+ provided below.
5
+
6
+ RUBY LICENSE
7
+
8
+ http://www.ruby-lang.org/en/LICENSE.txt
9
+
10
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
11
+ You can redistribute it and/or modify it under either the terms of the GPL
12
+ (see COPYING.txt file), or the conditions below:
13
+
14
+ 1. You may make and give away verbatim copies of the source form of the
15
+ software without restriction, provided that you duplicate all of the
16
+ original copyright notices and associated disclaimers.
17
+
18
+ 2. You may modify your copy of the software in any way, provided that
19
+ you do at least ONE of the following:
20
+
21
+ a) place your modifications in the Public Domain or otherwise
22
+ make them Freely Available, such as by posting said
23
+ modifications to Usenet or an equivalent medium, or by allowing
24
+ the author to include your modifications in the software.
25
+
26
+ b) use the modified software only within your corporation or
27
+ organization.
28
+
29
+ c) rename any non-standard executables so the names do not conflict
30
+ with standard executables, which must also be provided.
31
+
32
+ d) make other distribution arrangements with the author.
33
+
34
+ 3. You may distribute the software in object code or executable
35
+ form, provided that you do at least ONE of the following:
36
+
37
+ a) distribute the executables and library files of the software,
38
+ together with instructions (in the manual page or equivalent)
39
+ on where to get the original distribution.
40
+
41
+ b) accompany the distribution with the machine-readable source of
42
+ the software.
43
+
44
+ c) give non-standard executables non-standard names, with
45
+ instructions on where to get the original software distribution.
46
+
47
+ d) make other distribution arrangements with the author.
48
+
49
+ 4. You may modify and include the part of the software into any other
50
+ software (possibly commercial). But some files in the distribution
51
+ are not written by the author, so that they are not under this terms.
52
+
53
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
54
+ files under the ./missing directory. See each file for the copying
55
+ condition.
56
+
57
+ 5. The scripts and library files supplied as input to or produced as
58
+ output from the software do not automatically fall under the
59
+ copyright of the software, but belong to whomever generated them,
60
+ and may be sold commercially, and may be aggregated with this
61
+ software.
62
+
63
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
64
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
65
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
66
+ PURPOSE.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,68 @@
1
+ = AWS tools
2
+
3
+ == Note
4
+
5
+ This is very beta, use at your own risk. That said, I am using it production.
6
+
7
+ Until my filter patch gets pulled, you'll need to use this version of amazon-ec2:
8
+
9
+ https://github.com/stw/amazon-ec2/tree/add_filters_to_snapshots
10
+
11
+ == Description
12
+
13
+ A simple gem to provide aws command line tools, currently only snapshots. snapshots allows you to create snapshots from volumes on aws and deletes snapshots greater than the keep parameter.
14
+
15
+ == Usage
16
+
17
+ snapshots -v volume-id -k 2 -d "Some Description" -q
18
+
19
+ Creates a snapshot of volume-id, and deletes all snapshots except for the current and the last most recent.
20
+
21
+ == Installation
22
+
23
+ Ensure you set your amazon keys.
24
+
25
+ export EC2_PRIVATE_KEY=/path/to/private_key.pem
26
+ export EC2_CERT=/path/to/cert.pem
27
+
28
+ gem install awstools
29
+
30
+ snapshot -v volume-id -k 2 -d "Some Description"
31
+
32
+ snapshot --help for params
33
+
34
+ options:
35
+
36
+ Usage:
37
+ snapshots [options]
38
+
39
+ where [options] are:
40
+ --volume, -v <s>: Volume to snapshot
41
+ --keep, -k <i>: Snapshots to keep (default: 2)
42
+ --description, -d <s>: Snapshot description
43
+ --quiet, -q: Don't print anything
44
+ --simulate, -s: Simulate, nothing created/deleted
45
+ --help, -h: Show this message
46
+
47
+ == Reason
48
+
49
+ I looked for a simple tool to do this and didn't find anything I liked so I put this together.
50
+
51
+ == Contact
52
+
53
+ Comments, patches, Git pull requests and bug reports are welcome. Send an email to swalker@walkertek.com
54
+
55
+ == Patches & Pull Requests
56
+
57
+ Please follow these steps if you want to send a patch or a GitHub pull request:
58
+
59
+ * Fork stw/awstools
60
+ * Create a topic branch: `git checkout -b my_fix`
61
+ * Make sure you add tests for your changes and that they all pass with 'rake test'
62
+ * Don't change files that you don't own like the gemspec or version.rb
63
+ * Commit your changes, one change/fix per commit
64
+ * Push your fixes branch: `git push origin my_fix`
65
+ * Open an Issue on GitHub referencing your branch and send a pull request.
66
+ * Please do not push to `master` on your fork. Using a feature/bugfix branch will make everyone’s life easier.
67
+
68
+
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "awstools/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "awstools"
7
+ s.version = Awstools::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Stephen Walker"]
10
+ s.email = ["swalker@walkertek.com"]
11
+ s.homepage = "http://stephenwalker.com"
12
+ s.summary = %q{Tools to operate on aws}
13
+ s.description = %q{Right now, only snapshots.rb, creates and deletes snapshots}
14
+
15
+ s.rubyforge_project = "awstools"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ # swalker@walkertek.com - 2011-04-27
3
+
4
+ require 'rubygems'
5
+ require 'trollop'
6
+ require 'AWS'
7
+
8
+ # from cron
9
+ # create a daily snapshot, keep the last 2
10
+ # 0 0 * * * /path/to/snapshots.rb -v volume-id -k 7 -d "Some Snapshot Description"
11
+
12
+ options = Trollop::options do
13
+ banner <<-EOS
14
+ Take a snapshot of a volume and keep the latest <keep> snapshots, removing the rest
15
+
16
+ Usage:
17
+ snapshots [options]
18
+
19
+ where [options] are:
20
+ EOS
21
+
22
+ opt :volume, "Volume to snapshot", :type => String, :short => 'v', :required => true
23
+ opt :keep, "Snapshots to keep", :type => :int, :short => 'k', :default => 2
24
+ opt :description, "Snapshot description", :type => String, :short => 'd'
25
+ opt :quiet, "Don't print anything", :short => 'q'
26
+ opt :simulate, "Simulate, nothing created/deleted", :short => 's'
27
+ end
28
+
29
+ volume = options[:volume]
30
+ keep = options[:keep]
31
+ description = options[:description] || ''
32
+ quiet = options[:quiet] || false
33
+ simulate = options[:simulate] || false
34
+
35
+ @ec2 = AWS::EC2::Base.new(
36
+ :access_key_id => ENV['AMAZON_ACCESS_KEY_ID'],
37
+ :secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY'])
38
+
39
+ quiet or puts "Create new snapshot."
40
+ quiet or puts "Volume: #{volume} Description: #{description}"
41
+ begin
42
+ simulate or @ec2.create_snapshot(:volume_id => volume, :description => description)
43
+ rescue Exception => e
44
+ puts "Error: #{e.message}"
45
+ puts "Exiting"
46
+ exit
47
+ end
48
+
49
+ snapshots = @ec2.describe_snapshots(:filter_names => ['volume-id'], :filter_values => [volume])
50
+ snapshots = snapshots["snapshotSet"]["item"]
51
+
52
+ # sort by startTime desc
53
+ snapshots = snapshots.sort {|a,b| b.startTime <=> a.startTime }
54
+
55
+ # how many to remove, slices off end of array
56
+ remove = (snapshots.count - keep.to_i)
57
+ snapshots = snapshots.slice(-remove, remove)
58
+
59
+ snapshots && snapshots.each do |s|
60
+ quiet or puts "Removing..."
61
+ quiet or puts "Description: #{s.description}"
62
+ quiet or puts "snapshotId: #{s.snapshotId}"
63
+ quiet or puts "volumeId: #{s.volumeId}"
64
+ quiet or puts "startTime: #{s.startTime}"
65
+ quiet or puts
66
+ begin
67
+ simulate or @ec2.delete_snapshot(:snapshot_id => s.snapshotId)
68
+ rescue Exception => e
69
+ puts "Error: #{e.message}"
70
+ puts "Exiting"
71
+ exit
72
+ end
73
+ end
74
+
75
+ quiet or puts "Done."
@@ -0,0 +1,3 @@
1
+ module Awstools
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,3 @@
1
+ module Awstools
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awstools
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Stephen Walker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-27 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Right now, only snapshots.rb, creates and deletes snapshots
18
+ email:
19
+ - swalker@walkertek.com
20
+ executables:
21
+ - snapshots
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - Gemfile
29
+ - LICENSE
30
+ - Rakefile
31
+ - Readme.rdoc
32
+ - awstools.gemspec
33
+ - bin/snapshots
34
+ - lib/awstools.rb
35
+ - lib/awstools/version.rb
36
+ has_rdoc: true
37
+ homepage: http://stephenwalker.com
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project: awstools
60
+ rubygems_version: 1.6.2
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Tools to operate on aws
64
+ test_files: []
65
+