aws_tools 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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2010 Christopher Meiklejohn
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,6 @@
1
+ MIT-LICENSE
2
+ Manifest
3
+ README.rdoc
4
+ Rakefile
5
+ lib/aws_tools.rb
6
+ lib/aws_tools/s3.rb
data/README.rdoc ADDED
@@ -0,0 +1,66 @@
1
+ = Introduction
2
+
3
+ AwsTools aims to provide an interface to some common administration tasks.
4
+
5
+ = Installation
6
+
7
+ To install, run
8
+
9
+ $ sudo gem install aws_tools
10
+
11
+ = Examples
12
+
13
+ require 'rubygems'
14
+ require 'right_aws'
15
+ require 'aws_tools'
16
+
17
+ # Connect to S3 and synchronize all buckets.
18
+ AwsTools::S3::Synchronize.new(RightAws::S3.new(access_key,
19
+ secret_access_key,
20
+ :backup_suffix => "-dr",
21
+ :backup_location => :eu)
22
+
23
+ View the documentation for more information.
24
+
25
+ = Documentation
26
+
27
+ You can generate documentation if you have the source by typing:
28
+
29
+ rake doc
30
+
31
+ = Release Notes
32
+
33
+ First release.
34
+
35
+ = Credits
36
+
37
+ AwsTools is maintained by {Christopher Meiklejohn}[mailto:cmeik@me.com]. Contact me if you'd like to request any features or have any questions or feedback.
38
+
39
+ = License
40
+
41
+ AwsTools is Copyright 2010 Christopher Meiklejohn.
42
+
43
+ It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file, which is attached below:
44
+
45
+ Copyright (c) 2010 Christopher Meiklejohn
46
+
47
+ Permission is hereby granted, free of charge, to any person
48
+ obtaining a copy of this software and associated documentation
49
+ files (the "Software"), to deal in the Software without
50
+ restriction, including without limitation the rights to use,
51
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
52
+ copies of the Software, and to permit persons to whom the
53
+ Software is furnished to do so, subject to the following
54
+ conditions:
55
+
56
+ The above copyright notice and this permission notice shall be
57
+ included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
60
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
61
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
62
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
63
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
64
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
65
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
66
+ OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('aws_tools', '0.0.1') do |p|
6
+ p.description = "A library to help simplify common AWS tasks."
7
+ p.url = "http://github.com/cmeiklejohn/aws_tools"
8
+ p.author = "Christopher Meiklejohn"
9
+ p.email = "cmeik@me.com"
10
+ end
data/aws_tools.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{aws_tools}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Christopher Meiklejohn"]
9
+ s.date = %q{2010-02-25}
10
+ s.description = %q{A library to help simplify common AWS tasks.}
11
+ s.email = %q{cmeik@me.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/aws_tools.rb", "lib/aws_tools/s3.rb"]
13
+ s.files = ["MIT-LICENSE", "Manifest", "README.rdoc", "Rakefile", "lib/aws_tools.rb", "lib/aws_tools/s3.rb", "aws_tools.gemspec"]
14
+ s.homepage = %q{http://github.com/cmeiklejohn/aws_tools}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Aws_tools", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{aws_tools}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{A library to help simplify common AWS tasks.}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'right_aws'
5
+
6
+ module AwsTools
7
+ class S3
8
+ # Bucket class.
9
+ #
10
+ # Knows how to perform synchronization of all assets
11
+ # in one bucket.
12
+ class Bucket
13
+ # Synchronize.
14
+ #
15
+ # Performs the synchronization of one bucket.
16
+ class Synchronize
17
+ attr_accessor :bucket, :backup_bucket
18
+
19
+ def initialize(options = {})
20
+ puts "AwsTools::S3::Bucket::Synchronize called."
21
+
22
+ options.each_pair do |key, value|
23
+ self.send("#{key}=", value)
24
+ end
25
+
26
+ perform_synchronization
27
+ end
28
+
29
+ private
30
+
31
+ # Peform synchronization of one bucket.
32
+ def perform_synchronization
33
+ puts "AwsTools::S3::Bucket::Synchronize synchronizing #{bucket.name} to " +
34
+ "#{backup_bucket.name}"
35
+
36
+ bucket.keys.each do |source_key|
37
+
38
+ # Look for destination key.
39
+ destination_key = RightAws::S3::Key.create(backup_bucket, source_key.to_s)
40
+
41
+ # If it exists...
42
+ if destination_key.exists?
43
+
44
+ puts "AwsTools::S3::Bucket::Synchronize destination file #{source_key.to_s} " +
45
+ "already exists"
46
+
47
+ # Grab headers.
48
+ source_key.head
49
+ destination_key.head
50
+
51
+ # Get last modified
52
+ source_date = Time.parse(source_key.headers["last-modified"])
53
+ destination_date = Time.parse(destination_key.headers["last-modified"])
54
+
55
+ # Copy if the destination is older than the source
56
+ if source_date > destination_date
57
+ puts "AwsTools::S3::Bucket::Synchronize destination file #{source_key.to_s} " +
58
+ "is older"
59
+
60
+ # Perform a copy of the object.
61
+ source_key.copy(destination_key)
62
+
63
+ # Check if it worked...
64
+ if destination_key.exists?
65
+ puts "AwsTools::S3::Bucket::Synchronize destination file #{source_key.to_s} " +
66
+ "replaced with newer copy"
67
+ end
68
+ else
69
+ puts "AwsTools::S3::Bucket::Synchronize destination file #{source_key.to_s} " +
70
+ "is up to date"
71
+ end
72
+
73
+ else
74
+
75
+ # Perform a copy of the object.
76
+ source_key.copy(destination_key)
77
+
78
+ # Check if it worked...
79
+ if destination_key.exists?
80
+ puts "AwsTools::S3::Bucket::Synchronize destination file #{source_key.to_s} " +
81
+ "successfully created"
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+ end
90
+ end
91
+
92
+ # Synchronize class.
93
+ #
94
+ # Performs synchronization of every bucket in an S3 account.
95
+ #
96
+ # Assume that you will be synchronizing to a bucket with a suffix located
97
+ # in another zone (since names need to be unique across all zones.
98
+ class Synchronize
99
+ attr_accessor :backup_suffix, :backup_location
100
+
101
+ def initialize(s3, options = {})
102
+ puts "AwsTools::S3::Synchronize called."
103
+
104
+ @s3 = s3
105
+
106
+ options.each_pair do |key, value|
107
+ self.send("#{key}=", value)
108
+ end
109
+
110
+ perform_synchronization
111
+ end
112
+
113
+ private
114
+
115
+ # Retrieve all buckets, and synchronize them one by one.
116
+ def perform_synchronization
117
+ # Retrieve bucket list.
118
+ @s3.buckets.each do |bucket|
119
+ puts "AwsTools::S3::Synchronize assesing bucket #{bucket.name}"
120
+
121
+ # If the bucket is located in the normal zone, assume this
122
+ # is a bucket we want to create a backup of.
123
+ if bucket.location.empty?
124
+
125
+ # Backup bucket.
126
+ backup_bucket_name = "#{bucket.name}#{backup_suffix}"
127
+
128
+ puts "AwsTools::S3::Synchronize #{bucket.name} will be synchronized " +
129
+ "to #{backup_bucket_name} in #{backup_location}"
130
+
131
+ backup_bucket = @s3.bucket("#{backup_bucket_name}",
132
+ true,
133
+ 'public-read',
134
+ :location => backup_location)
135
+
136
+ AwsTools::S3::Bucket::Synchronize.new(:bucket => bucket,
137
+ :backup_bucket => backup_bucket)
138
+ end
139
+ end
140
+ end
141
+
142
+ end
143
+ end
144
+ end
data/lib/aws_tools.rb ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # AwsTools
4
+ #
5
+ # Provides an interface to make some AWS administration tools easier.
6
+ #
7
+ # Author:: Christopher Meiklejohn (cmeik@me.com)
8
+ # Copyright:: Copyright (c) 2010 Christopher Meiklejohn
9
+ # License:: Distributes under the terms specified in the MIT-LICENSE file.
10
+ #
11
+ # Usage example:
12
+ #
13
+ # # Connect to S3 and synchronize all buckets.
14
+ # AwsTools::S3::Synchronize.new(RightAws::S3.new(access_key,
15
+ # secret_access_key,
16
+ # :backup_suffix => "-dr",
17
+ # :backup_location => :eu)
18
+ #
19
+ #
20
+ require 'rubygems'
21
+ require 'right_aws'
22
+
23
+ $:.unshift(File.dirname(__FILE__))
24
+ require 'aws_tools/s3'
25
+
26
+ module AwsTools #:nodoc:
27
+ module VERSION #:nodoc:
28
+ MAJOR = 0
29
+ MINOR = 0
30
+ TINY = 1
31
+
32
+ STRING = [MAJOR, MINOR, TINY].join('.')
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Christopher Meiklejohn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-25 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A library to help simplify common AWS tasks.
17
+ email: cmeik@me.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - lib/aws_tools.rb
25
+ - lib/aws_tools/s3.rb
26
+ files:
27
+ - MIT-LICENSE
28
+ - Manifest
29
+ - README.rdoc
30
+ - Rakefile
31
+ - lib/aws_tools.rb
32
+ - lib/aws_tools/s3.rb
33
+ - aws_tools.gemspec
34
+ has_rdoc: true
35
+ homepage: http://github.com/cmeiklejohn/aws_tools
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --line-numbers
41
+ - --inline-source
42
+ - --title
43
+ - Aws_tools
44
+ - --main
45
+ - README.rdoc
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "1.2"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project: aws_tools
63
+ rubygems_version: 1.3.5
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: A library to help simplify common AWS tasks.
67
+ test_files: []
68
+