undertaker-s3 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/LICENSE +20 -0
- data/README.md +18 -0
- data/bin/undertaker-s3 +122 -0
- data/undertaker-s3.gemspec +16 -0
- metadata +113 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Akhil Bansal, Carlos Peñas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
This ruby script that takes backup of git repository to Amazon S3.
|
2
|
+
|
3
|
+
For more details read here: http://vinsol.com/blog/2011/05/16/github2s3-backup-github-repositories-to-amazon-s3/
|
4
|
+
|
5
|
+
This fork no longer support yml as a way to specify more than one repo.
|
6
|
+
|
7
|
+
```
|
8
|
+
Options:
|
9
|
+
--n, -n: dry-run
|
10
|
+
--repo, -r <s>: Clone Repository
|
11
|
+
--bucket, -b <s>: Bucket name
|
12
|
+
--debug, -d: debug flag
|
13
|
+
--aws-access-key-id, -a: AWS access key ID
|
14
|
+
--aws-secret-access-key, -w: AWS secret access key
|
15
|
+
--help, -h: Show this message
|
16
|
+
```
|
17
|
+
|
18
|
+
|
data/bin/undertaker-s3
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#############################################################
|
3
|
+
# Author: Akhil Bansal (http://webonrails.com)
|
4
|
+
#############################################################
|
5
|
+
|
6
|
+
USE_SSL = true
|
7
|
+
|
8
|
+
require 'trollop'
|
9
|
+
require 'rubygems'
|
10
|
+
require 'fileutils'
|
11
|
+
require 'aws/s3'
|
12
|
+
require 'yaml'
|
13
|
+
require "colorize"
|
14
|
+
|
15
|
+
$opts = Trollop::options do
|
16
|
+
opt :repo, 'Clone Repository', :type => :string
|
17
|
+
opt :bucket, 'Bucket name', :type => :string
|
18
|
+
opt :debug, 'debug flag', :default => false
|
19
|
+
opt :aws_access_key_id, 'AWS access key ID', :default => ENV['AWS_ACCESS_KEY_ID']
|
20
|
+
opt :aws_secret_access_key, 'AWS secret access key', :default => ENV['AWS_SECRET_ACCESS_KEY']
|
21
|
+
end
|
22
|
+
|
23
|
+
puts "options: " if $opts[:debug]
|
24
|
+
p $opts if $opts[:debug]
|
25
|
+
|
26
|
+
AWS::S3::Base.establish_connection!(
|
27
|
+
:access_key_id => $opts[:aws_access_key_id],
|
28
|
+
:secret_access_key => $opts[:aws_secret_access_key],
|
29
|
+
:use_ssl => USE_SSL
|
30
|
+
)
|
31
|
+
|
32
|
+
class Bucket < AWS::S3::Bucket
|
33
|
+
end
|
34
|
+
|
35
|
+
class S3Object < AWS::S3::S3Object
|
36
|
+
end
|
37
|
+
|
38
|
+
def clone_and_upload_to_s3(options)
|
39
|
+
puts "\n\nChecking out #{options[:name]} ...".green
|
40
|
+
clone_command = "cd #{$opts[:bucket]} && git clone --bare #{options[:clone_url]} #{options[:name]}"
|
41
|
+
puts clone_command.yellow
|
42
|
+
system(clone_command)
|
43
|
+
puts "\n Compressing #{options[:name]} ".green
|
44
|
+
system("cd #{$opts[:bucket]} && tar czf #{compressed_filename(options[:name])} #{options[:name]}")
|
45
|
+
|
46
|
+
upload_to_s3(compressed_filename(options[:name]))
|
47
|
+
end
|
48
|
+
|
49
|
+
def compressed_filename(str)
|
50
|
+
str+".tar.gz"
|
51
|
+
end
|
52
|
+
|
53
|
+
def upload_to_s3(filename)
|
54
|
+
begin
|
55
|
+
puts "** Uploading #{filename} to S3".green
|
56
|
+
path = File.join($opts[:bucket], filename)
|
57
|
+
S3Object.store(filename, File.read(path), s3bucket)
|
58
|
+
rescue Exception => e
|
59
|
+
puts "Could not upload #{filename} to S3".red
|
60
|
+
puts e.message.red
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete_dir_and_sub_dir(dir)
|
65
|
+
Dir.foreach(dir) do |e|
|
66
|
+
# Don't bother with . and ..
|
67
|
+
next if [".",".."].include? e
|
68
|
+
fullname = dir + File::Separator + e
|
69
|
+
if FileTest::directory?(fullname)
|
70
|
+
delete_dir_and_sub_dir(fullname)
|
71
|
+
else
|
72
|
+
File.delete(fullname)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
Dir.delete(dir)
|
76
|
+
end
|
77
|
+
|
78
|
+
def ensure_bucket_exists
|
79
|
+
begin
|
80
|
+
bucket = Bucket.find(s3bucket)
|
81
|
+
rescue AWS::S3::NoSuchBucket => e
|
82
|
+
puts "Bucket '#{s3bucket}' not found."
|
83
|
+
puts "Creating Bucket '#{s3bucket}'. "
|
84
|
+
|
85
|
+
begin
|
86
|
+
Bucket.create(s3bucket)
|
87
|
+
puts "Created Bucket '#{s3bucket}'. "
|
88
|
+
rescue Exception => e
|
89
|
+
puts e.message
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def s3bucket
|
95
|
+
s3bucket = $opts[:bucket]
|
96
|
+
end
|
97
|
+
|
98
|
+
def backup_repo
|
99
|
+
begin
|
100
|
+
name = $opts[:repo].split('/').last
|
101
|
+
clone_and_upload_to_s3(:name => name, :clone_url => $opts[:repo])
|
102
|
+
rescue Exception => e
|
103
|
+
puts e.message.red
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
Trollop::die :repo, ' Need a repo to clone' unless $opts[:repo]
|
109
|
+
Trollop::die :aws_secret_access_key, ' Secret access key needed' unless $opts[:aws_secret_access_key]
|
110
|
+
Trollop::die :aws_access_key_id, ' Access key needed' unless $opts[:aws_access_key_id]
|
111
|
+
Trollop::die :bucket, ' need a bucket to upload' unless $opts[:bucket]
|
112
|
+
|
113
|
+
begin
|
114
|
+
# create temp dir
|
115
|
+
Dir.mkdir($opts[:bucket]) rescue nil
|
116
|
+
ensure_bucket_exists
|
117
|
+
backup_repo
|
118
|
+
ensure
|
119
|
+
# remove temp dir
|
120
|
+
delete_dir_and_sub_dir($opts[:bucket])
|
121
|
+
end
|
122
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'undertaker-s3'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.authors = ["Carlos Peñas"]
|
5
|
+
s.date = Time.now.utc.strftime('%Y-%m-%d')
|
6
|
+
s.email = 'carlos.penas@the-cocktail.com'
|
7
|
+
s.summary = "Git bare backup in amazon s3 bucket"
|
8
|
+
|
9
|
+
s.files = `git ls-files`.split($\)
|
10
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
11
|
+
|
12
|
+
s.add_dependency('colorize')
|
13
|
+
s.add_dependency('trollop')
|
14
|
+
s.add_dependency('aws-s3')
|
15
|
+
s.add_dependency('fileutils')
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: undertaker-s3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Carlos Peñas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: colorize
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: trollop
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: aws-s3
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: fileutils
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description:
|
79
|
+
email: carlos.penas@the-cocktail.com
|
80
|
+
executables:
|
81
|
+
- undertaker-s3
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- LICENSE
|
86
|
+
- README.md
|
87
|
+
- bin/undertaker-s3
|
88
|
+
- undertaker-s3.gemspec
|
89
|
+
homepage:
|
90
|
+
licenses: []
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.8.23
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Git bare backup in amazon s3 bucket
|
113
|
+
test_files: []
|