parachute 0.1.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 +15 -0
- data/.gitignore +5 -0
- data/LICENSE +21 -0
- data/README.md +1 -0
- data/bin/parachute +6 -0
- data/lib/parachute.rb +3 -0
- data/lib/parachute/backup.rb +69 -0
- data/lib/parachute/version.rb +3 -0
- data/parachute.gemspec +15 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjU5ZTljMDBjZTRhZDVkY2VlNzYxMTUzZTU3MWUzNDBjMTNkZGRlZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWNkZjUyMjM3MzhhYjdiNmQ5ZTg5NGY1MGNmMTBlMGYxODMzZTZkMA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MWVjNDg0N2JiM2U4NDdiZTgzZTU3YzUxZmNjMDkyMWFiNDUyNTk1YjkyYjUw
|
10
|
+
MTFjZWY2NTZmN2M4NzM3NmJiZDkyMjhmOGE4ZTExMDViNDg2NWUzY2Y3NTY3
|
11
|
+
MzY1Njk3MzdkNjdiMjc2YWJmNDVmNmI0ZWViNzNhODg1NDZiZWU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Nzc5NzgwMWZiOTM2NDA5Yzg5ZDBiYzI2YzA0NTQ2NGZjNTkxNTMwYzU1M2I4
|
14
|
+
YmRkZDY4NzIwODUxZTExNDBlMzg5YmNlMzA3MzQ0OWNhYWNjMGNkYWE4NjI2
|
15
|
+
MWUzMWQwMTg5MzUxMTE4MTI2MzExNmUzZjdlZTlkODJiZmUxZmE=
|
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 Luca Cervasio
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
A backup system wrapping rsync using hard links.
|
data/bin/parachute
ADDED
data/lib/parachute.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Parachute
|
6
|
+
|
7
|
+
class Backup
|
8
|
+
|
9
|
+
def initialize filename='parachute.yml'
|
10
|
+
@servers = ::YAML::load_file(filename)
|
11
|
+
$path = '/share/MD0_DATA/backup'
|
12
|
+
end
|
13
|
+
|
14
|
+
def run_backup(server, fqdn, folder)
|
15
|
+
print "running backup of folder #{folder} on #{server}[#{fqdn}]..."
|
16
|
+
t = Time.now
|
17
|
+
date = t.strftime("%Y-%m-%d_%H.%M")
|
18
|
+
|
19
|
+
cmd1 = "rsync --archive --one-file-system --hard-links --human-readable --inplace --numeric-ids --delete --verbose --compress --link-dest=#{$path}/#{server}/_#{folder}_#{server}.current root@#{fqdn}:/#{folder}/ #{$path}/#{server}/_#{folder}_#{server}.#{date}/"
|
20
|
+
cmd2 = "rm #{$path}/#{server}/_#{folder}_#{server}.current"
|
21
|
+
cmd3 = "ln -s #{$path}/#{server}/_#{folder}_#{server}.#{date} #{$path}/#{server}/_#{folder}_#{server}.current"
|
22
|
+
|
23
|
+
start = Time.now
|
24
|
+
out = `#{cmd1}`
|
25
|
+
out =~ /total size is ([\d|\.|B|G|M|K|T]+)/
|
26
|
+
disk_usage = $1
|
27
|
+
out =~ /received ([\d|\.|B|G|M|K|T]+)/
|
28
|
+
received = $1
|
29
|
+
stop = Time.now
|
30
|
+
|
31
|
+
out = `#{cmd2}`
|
32
|
+
out = `#{cmd3}`
|
33
|
+
|
34
|
+
puts " done in #{(stop-start).round(1).to_s}s - disk usage = #{disk_usage}, received data = #{received}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def rotate(server)
|
38
|
+
#puts $path + "/" + server
|
39
|
+
print "rotating #{server} backups..."
|
40
|
+
today = Date.today
|
41
|
+
Dir.entries($path + "/" + server).each do |f|
|
42
|
+
if f =~ /(\d\d\d\d\-\d\d\-\d\d)/
|
43
|
+
d = Date.strptime $1, "%Y-%m-%d"
|
44
|
+
if d > today - 30 or (d.day < 10 and d.wday == 2 and d > today-120)
|
45
|
+
#puts "lo tengo"
|
46
|
+
else
|
47
|
+
#print "#{f} from date #{d}..."
|
48
|
+
FileUtils.rm_rf($path + "/" + server + "/" + f)
|
49
|
+
#puts "deleted !"
|
50
|
+
print "#"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
puts " done"
|
55
|
+
end
|
56
|
+
|
57
|
+
def run
|
58
|
+
servers.each do |hostname,server|
|
59
|
+
server['folders'].each do |folder|
|
60
|
+
run_backup(hostname, server['fqdn'], folder)
|
61
|
+
end
|
62
|
+
rotate(hostname)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
data/parachute.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require './lib/parachute/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'parachute'
|
5
|
+
spec.version = Parachute::VERSION
|
6
|
+
spec.date = Date.today.to_s
|
7
|
+
spec.summary = "A backup system"
|
8
|
+
spec.description = "A wrapper around rsync for backing up your remote servers and archiving using hard links."
|
9
|
+
spec.authors = ["Luca Cervasio"]
|
10
|
+
spec.email = 'luca.cervasio@gmail.com'
|
11
|
+
spec.files = `git ls-files`.split($/)
|
12
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
|
+
spec.homepage = 'https://github.com/lucacervasio/parachute'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parachute
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luca Cervasio
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A wrapper around rsync for backing up your remote servers and archiving
|
14
|
+
using hard links.
|
15
|
+
email: luca.cervasio@gmail.com
|
16
|
+
executables:
|
17
|
+
- parachute
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- LICENSE
|
23
|
+
- README.md
|
24
|
+
- bin/parachute
|
25
|
+
- lib/parachute.rb
|
26
|
+
- lib/parachute/backup.rb
|
27
|
+
- lib/parachute/version.rb
|
28
|
+
- parachute.gemspec
|
29
|
+
homepage: https://github.com/lucacervasio/parachute
|
30
|
+
licenses:
|
31
|
+
- MIT
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 2.2.2
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: A backup system
|
53
|
+
test_files: []
|
54
|
+
has_rdoc:
|