backup_aws_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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +2 -0
- data/backup_aws_s3.gemspec +27 -0
- data/lib/backup_aws_s3/version.rb +3 -0
- data/lib/backup_aws_s3.rb +88 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 70d10ce6d25bc4d078ce1bd100563e3aa99f69ec
|
4
|
+
data.tar.gz: a74da455147b39997f8823e98f1d82ab00473898
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a4eb710d87e6bebb8ec4d021c9654936d21cccdcf0863a6003c655628d9c7276180f83656035eec2039ae98fed47a92c869337dded01504e865abe64d31bbb0
|
7
|
+
data.tar.gz: 18b7f33103eed7249e9200f05796c1c641837fcc705ea9efd7f8ce5df28945f57694bdd58687e69121270c6cc1abd0ed055b9b8f246f2af1fb0aed03d3517c08
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Rodrigo Mendonca
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# BackupAwsS3
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'backup_aws_s3'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install backup_aws_s3
|
20
|
+
|
21
|
+
## Pre-Requisites Installss
|
22
|
+
|
23
|
+
## Install s3s3mirror
|
24
|
+
|
25
|
+
In your terminal
|
26
|
+
|
27
|
+
$ cd ~
|
28
|
+
$ git clone git@github.com:cobbzilla/s3s3mirror.git
|
29
|
+
|
30
|
+
$ sudo apt-get install s3cmd
|
31
|
+
|
32
|
+
Insert you aws keys
|
33
|
+
$ s3cmd --configure
|
34
|
+
|
35
|
+
|
36
|
+
$ sudo touch /var/log/s3s3mirror.log
|
37
|
+
$ sudo chmod 777 /var/log/s3s3mirror.log
|
38
|
+
|
39
|
+
## Create Enviroment Variables
|
40
|
+
|
41
|
+
export S3_BUCKET_BACKUP="xxxxxxxxxxx"
|
42
|
+
export S3_ACCESS_KEY_ID="xxxxxxxxxxx"
|
43
|
+
export S3_SECRET_KEY_ID="xxxxxxxxxxx"
|
44
|
+
S3S3MIRROR_PATH='/home/USERNAME/s3s3mirror'
|
45
|
+
|
46
|
+
##. Usage
|
47
|
+
|
48
|
+
$ ruby backup_uploads.rb identification_name source dest keep
|
49
|
+
|
50
|
+
Example
|
51
|
+
# erp
|
52
|
+
$ ruby backup_uploads.rb "erp_ultimos_30_dias" "scproduction/" "${S3_BUCKET_BACKUP}/upload_files/erp/$(date +%Y.%m.%d.%H.%M.%S)/" 30
|
53
|
+
$ ruby backup_uploads.rb "erp_20_em_20_minutos" "scproduction/" "${S3_BUCKET_BACKUP}/upload_files/erp/$(date +%Y.%m.%d.%H.%M.%S)/" 216
|
54
|
+
# redmine
|
55
|
+
$ ruby backup_uploads.rb "redmine_ultimos_30_dias" "redmineseucondominioproduction/" "${S3_BUCKET_BACKUP}/upload_files/redmine/$(date +%Y.%m.%d.%H.%M.%S)/" 30
|
56
|
+
$ ruby backup_uploads.rb "redmine_20_em_20_minutos" "redmineseucondominioproduction/" "${S3_BUCKET_BACKUP}/upload_files/redmine/$(date +%Y.%m.%d.%H.%M.%S)/" 316
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it ( https://github.com/[my-github-username]/backup_aws_s3/fork )
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'backup_aws_s3/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "backup_aws_s3"
|
8
|
+
spec.version = BackupAwsS3::VERSION
|
9
|
+
spec.authors = ["Rodrigo Mendonca"]
|
10
|
+
spec.email = ["denoww@gmail.com"]
|
11
|
+
spec.summary = %q{Backup folders storaged in aws s3.}
|
12
|
+
spec.description = %q{Backup folders storaged in aws s3.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "manage_s3_bucket"
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "backup_aws_s3/version"
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
require 'manage_s3_bucket'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
# no docs
|
9
|
+
class BackupS3
|
10
|
+
def initialize(opt = {})
|
11
|
+
create opt
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(opt = {})
|
15
|
+
name = opt[:name]
|
16
|
+
dest = opt[:dest]
|
17
|
+
p "Creating backup: #{name} in #{dest} "
|
18
|
+
Open3.popen3('nroff -man') do |stdin, stdout, stderr|
|
19
|
+
# system "cd #{ENV['S3S3MIRROR_PATH']} && ./s3s3mirror.sh #{opt[:source]} #{dest}"
|
20
|
+
# p "Created backup: #{name} in #{dest} "
|
21
|
+
BackupS3::Cycler.new(name).cycle!(path: dest, keep: opt[:keep])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# no docs
|
26
|
+
class Cycler
|
27
|
+
def initialize(name)
|
28
|
+
@name = name
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove!(directory)
|
32
|
+
p "Removing old backup: #{directory}"
|
33
|
+
s3 = Manage::S3::new(ENV['S3_ACCESS_KEY_ID'], ENV['S3_SECRET_KEY_ID'])
|
34
|
+
s3.remove_path(directory)
|
35
|
+
p "Removed old backup: #{directory}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def cycle!(opt = {})
|
39
|
+
backups = yaml_load.unshift(
|
40
|
+
path: opt[:path],
|
41
|
+
time: Time.now.strftime('%Y.%m.%d.%H.%M.%S')
|
42
|
+
)
|
43
|
+
excess = backups.count - opt[:keep].to_i
|
44
|
+
if excess > 0
|
45
|
+
backups.pop(excess).each do |backup|
|
46
|
+
begin
|
47
|
+
remove!(backup[:path])
|
48
|
+
rescue => err
|
49
|
+
p "Error removing old backups: #{err}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
yaml_save(backups)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns path to the YAML data file.
|
57
|
+
def yaml_file
|
58
|
+
@yaml_file ||= begin
|
59
|
+
File.join('.data', 'last_s3_backups', "#{ @name }.yml")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns stored Package objects, sorted by #time descending (oldest last).
|
64
|
+
def yaml_load
|
65
|
+
if File.exist?(yaml_file) && !File.zero?(yaml_file)
|
66
|
+
# raise YAML.load_file(yaml_file).inspect
|
67
|
+
YAML.load_file(yaml_file).sort_by!{|b| b[:time]}.reverse!
|
68
|
+
else
|
69
|
+
[]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Stores the given package objects to the YAML data file.
|
74
|
+
def yaml_save(backups)
|
75
|
+
FileUtils.mkdir_p(File.dirname(yaml_file))
|
76
|
+
File.open(yaml_file, 'w') do |file|
|
77
|
+
file.write(backups.to_yaml)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
BackupS3.new(
|
84
|
+
name: ARGV[0],
|
85
|
+
source: ARGV[1],
|
86
|
+
dest: ARGV[2],
|
87
|
+
keep: ARGV[3]
|
88
|
+
)
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backup_aws_s3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodrigo Mendonca
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: manage_s3_bucket
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Backup folders storaged in aws s3.
|
56
|
+
email:
|
57
|
+
- denoww@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- backup_aws_s3.gemspec
|
68
|
+
- lib/backup_aws_s3.rb
|
69
|
+
- lib/backup_aws_s3/version.rb
|
70
|
+
homepage: ''
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.4.6
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Backup folders storaged in aws s3.
|
94
|
+
test_files: []
|