s3copy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +19 -0
- data/bin/s3copy +42 -0
- data/lib/commandline.rb +72 -0
- data/s3copy.gemspec +25 -0
- metadata +73 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/bin/s3copy
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'commandline'
|
3
|
+
require 's3'
|
4
|
+
|
5
|
+
args = S3Copy::CommandLine.new(ARGV)
|
6
|
+
|
7
|
+
if args.missing_arguments?
|
8
|
+
args.show_help
|
9
|
+
exit
|
10
|
+
else
|
11
|
+
# connect up to S3
|
12
|
+
in_service = S3::Service.new(:access_key_id => args.in_key, :secret_access_key => args.in_secret)
|
13
|
+
out_service = S3::Service.new(:access_key_id => (args.out_key || args.in_key),
|
14
|
+
:secret_access_key => (args.out_secret || args.in_secret))
|
15
|
+
|
16
|
+
# get the buckets
|
17
|
+
in_bucket = in_service.buckets.find(args.in_bucket)
|
18
|
+
out_bucket = in_service.buckets.find(args.out_bucket)
|
19
|
+
|
20
|
+
# get object lists
|
21
|
+
objects = []
|
22
|
+
if args.all.nil?
|
23
|
+
key = STDIN.gets
|
24
|
+
while !key.nil?
|
25
|
+
key.chomp!
|
26
|
+
object = in_bucket.object(key)
|
27
|
+
objects << object
|
28
|
+
key = STDIN.gets
|
29
|
+
end
|
30
|
+
else
|
31
|
+
objects = in_bucket.objects
|
32
|
+
end
|
33
|
+
|
34
|
+
# begin copy
|
35
|
+
objects.each do |object|
|
36
|
+
copy = out_bucket.objects.build(object.key)
|
37
|
+
copy.content = object.content
|
38
|
+
copy.content_type = object.content_type
|
39
|
+
copy.save
|
40
|
+
puts "Copied #{object.key}"
|
41
|
+
end
|
42
|
+
end
|
data/lib/commandline.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'granicus-platform-api'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
module S3Copy
|
6
|
+
class CommandLine
|
7
|
+
attr_accessor :in_key, :in_secret, :in_bucket, :out_key, :out_secret, :out_bucket, :all
|
8
|
+
|
9
|
+
def initialize(args)
|
10
|
+
# Handle options
|
11
|
+
options = {}
|
12
|
+
@option_parser = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: #{opts.program_name} [options]"
|
14
|
+
opts.separator ""
|
15
|
+
opts.separator "Specific options:"
|
16
|
+
|
17
|
+
# in key
|
18
|
+
opts.on(:REQUIRED,"--in_key S3KEY","The S3 amazon key to use for the in bucket.") do |val|
|
19
|
+
@in_key = val
|
20
|
+
end
|
21
|
+
|
22
|
+
# in secret
|
23
|
+
opts.on(:REQUIRED,"--in_secret S3SECRET","The S3 amazon secret to use for the in bucket.") do |val|
|
24
|
+
@in_secret = val
|
25
|
+
end
|
26
|
+
|
27
|
+
# in bucket
|
28
|
+
opts.on(:REQUIRED,"--in_bucket BUCKET","The name of the bucket to copy from.") do |val|
|
29
|
+
@in_bucket = val
|
30
|
+
end
|
31
|
+
|
32
|
+
# out key
|
33
|
+
opts.on(:REQUIRED,"--out_key S3KEY","The S3 amazon key to use for the out bucket.") do |val|
|
34
|
+
@out_key = val
|
35
|
+
end
|
36
|
+
|
37
|
+
# out secret
|
38
|
+
opts.on(:REQUIRED,"--out_secret S3SECRET","The S3 amazon secret to use for the out bucket.") do |val|
|
39
|
+
@out_secret = val
|
40
|
+
end
|
41
|
+
|
42
|
+
# out bucket
|
43
|
+
opts.on(:REQUIRED,"--out_bucket BUCKET","The name of the bucket to copy to.") do |val|
|
44
|
+
@out_bucket = val
|
45
|
+
end
|
46
|
+
|
47
|
+
# all files
|
48
|
+
opts.on(:OPTIONAL,"--all","Copy all of the files. If this is omitted filenames will be read from STDIN.") do |val|
|
49
|
+
@all = val
|
50
|
+
end
|
51
|
+
|
52
|
+
# No argument, shows at tail. This will print an options summary.
|
53
|
+
opts.on_tail("-?", "--help", "Show this message") do
|
54
|
+
puts opts
|
55
|
+
exit
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# parse options
|
60
|
+
@option_parser.parse!(ARGV)
|
61
|
+
end
|
62
|
+
|
63
|
+
def show_help
|
64
|
+
puts @option_parser
|
65
|
+
end
|
66
|
+
|
67
|
+
def missing_arguments?
|
68
|
+
return (@in_key.nil? or @in_secret.nil? or @in_bucket.nil? or @out_bucket.nil?)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
data/s3copy.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "s3copy"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Javier Muniz"]
|
9
|
+
s.email = "javier@granicus.com"
|
10
|
+
s.summary = "Simple library and command line tool for copying files between S3 buckets."
|
11
|
+
s.homepage = "http://github.com/granicus/s3copy"
|
12
|
+
s.description = "Simple library and command line tool for copying files between S3 buckets."
|
13
|
+
|
14
|
+
s.rubyforge_project = "s3copy"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency('s3', '>= 0.3.11')
|
22
|
+
|
23
|
+
s.add_dependency('s3', '>= 0.3.11')
|
24
|
+
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: s3copy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Javier Muniz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: s3
|
16
|
+
requirement: &2164382480 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.11
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2164382480
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: s3
|
27
|
+
requirement: &2164381840 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.3.11
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2164381840
|
36
|
+
description: Simple library and command line tool for copying files between S3 buckets.
|
37
|
+
email: javier@granicus.com
|
38
|
+
executables:
|
39
|
+
- s3copy
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- Gemfile.lock
|
46
|
+
- bin/s3copy
|
47
|
+
- lib/commandline.rb
|
48
|
+
- s3copy.gemspec
|
49
|
+
homepage: http://github.com/granicus/s3copy
|
50
|
+
licenses: []
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project: s3copy
|
69
|
+
rubygems_version: 1.8.5
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Simple library and command line tool for copying files between S3 buckets.
|
73
|
+
test_files: []
|