encbs 0.2.1.alpha → 0.2.1.beta1
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/VERSION +1 -1
- data/bin/encbs +12 -4
- data/encbs.gemspec +2 -2
- data/lib/archive.rb +1 -1
- data/lib/backup/file_item/cloud.rb +24 -4
- data/lib/backup/file_item/local.rb +14 -6
- data/lib/backup/jar.rb +14 -3
- data/lib/backup.rb +8 -8
- data/lib/encbsconfig.rb +5 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.1.
|
1
|
+
0.2.1.beta1
|
data/bin/encbs
CHANGED
@@ -39,12 +39,13 @@ begin
|
|
39
39
|
on :k, :key, "Set API key to access Amazon S3", true
|
40
40
|
on :l, :local, "Backup in local directory", true
|
41
41
|
on :list, "List of jars"
|
42
|
+
on :p, :purge, "Remove previous backup(s)"
|
42
43
|
on :r, :rescue, "Return data from backup (option: jar, path or filter)", true
|
43
44
|
on :s, :secret, "Set API secret to access Amazon S3", true
|
45
|
+
on :size, "RSA private key length (default: 4096)", true
|
44
46
|
on :t, :to, "Path to recovery (default: /)", true
|
45
47
|
on :timeout, "Timeout(sec) to try pushing into cloud (default: 60s)", true
|
46
48
|
on :token, "RSA key to encrypt/decrypt backup data", true
|
47
|
-
on :size, "RSA private key length (default: 4096)", true
|
48
49
|
on :v, :verbose, "Verbose mode"
|
49
50
|
|
50
51
|
banner "Usage:\n $ encbs [options]\n\nOptions:"
|
@@ -225,7 +226,7 @@ begin
|
|
225
226
|
exit
|
226
227
|
end
|
227
228
|
|
228
|
-
if
|
229
|
+
if !@config.paths.nil? or opts.add?
|
229
230
|
if File.exists? "/var/tmp/encbs.swap"
|
230
231
|
meta = YAML::load open("/var/tmp/encbs.swap").read
|
231
232
|
jar_path, timestamp = meta[:jar_path], meta[:timestamp]
|
@@ -258,11 +259,18 @@ begin
|
|
258
259
|
end
|
259
260
|
|
260
261
|
paths.each do |path|
|
261
|
-
|
262
|
+
unless opts.increment?
|
263
|
+
purge = @config.purge || opts.purge?
|
264
|
+
else
|
265
|
+
purge = false
|
266
|
+
end
|
267
|
+
|
268
|
+
increment = @config.increment || opts.increment?
|
269
|
+
@backup.create! path, increment, purge
|
262
270
|
end
|
263
271
|
|
264
272
|
puts "Done!".green
|
265
273
|
end
|
266
274
|
ensure
|
267
275
|
remove_lock
|
268
|
-
end
|
276
|
+
end
|
data/encbs.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{encbs}
|
8
|
-
s.version = "0.2.1.
|
8
|
+
s.version = "0.2.1.beta1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Timothy Klim"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-24}
|
13
13
|
s.default_executable = %q{encbs}
|
14
14
|
s.description = %q{Simple backup system for pushing into cloud}
|
15
15
|
s.email = %q{klimtimothy@gmail.com}
|
data/lib/archive.rb
CHANGED
@@ -14,9 +14,9 @@ module Backup
|
|
14
14
|
end
|
15
15
|
@timeout = 60
|
16
16
|
|
17
|
-
try_to_connect_with_cloud
|
17
|
+
try_to_connect_with_cloud
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def timeout=(time)
|
21
21
|
@timeout = time
|
22
22
|
end
|
@@ -24,6 +24,26 @@ module Backup
|
|
24
24
|
def create_directory_once(*directories)
|
25
25
|
end
|
26
26
|
|
27
|
+
def delete_file path
|
28
|
+
try_to_work_with_cloud do
|
29
|
+
file = delete_slashes(path)
|
30
|
+
@directory.files.get(file).destroy
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete_dir directory
|
35
|
+
try_to_work_with_cloud do
|
36
|
+
path = delete_slashes(directory)
|
37
|
+
|
38
|
+
files = @directory.files.all(
|
39
|
+
:prefix => path,
|
40
|
+
:max_keys => 30_000
|
41
|
+
).map do |file|
|
42
|
+
file.destroy
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
27
47
|
def create_file_once(file, data)
|
28
48
|
try_to_work_with_cloud do
|
29
49
|
@directory.files.create(
|
@@ -49,7 +69,7 @@ module Backup
|
|
49
69
|
:prefix => path,
|
50
70
|
:max_keys => 30_000
|
51
71
|
).map(&:key)
|
52
|
-
|
72
|
+
|
53
73
|
files.map do |item|
|
54
74
|
match = item.match(/^#{path}\/([^\/]+#{mask}).*$/)
|
55
75
|
match[1] if match
|
@@ -93,4 +113,4 @@ module Backup
|
|
93
113
|
end
|
94
114
|
end
|
95
115
|
end
|
96
|
-
end
|
116
|
+
end
|
@@ -9,25 +9,25 @@ module Backup
|
|
9
9
|
@timeout = 0
|
10
10
|
end
|
11
11
|
|
12
|
-
def create_directory_once
|
12
|
+
def create_directory_once *directories
|
13
13
|
directories.each do |path|
|
14
14
|
FileUtils.mkdir_p(path) unless Dir.exists?(path)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def create_file_once
|
18
|
+
def create_file_once file, data
|
19
19
|
data = data.read if data.is_a? File or data.is_a? StringIO
|
20
20
|
File.open(file, "wb").puts(data) unless File.exists?(file)
|
21
21
|
end
|
22
22
|
|
23
|
-
def read_file
|
23
|
+
def read_file file
|
24
24
|
File.open(file, 'rb').read if File.exists? file
|
25
25
|
end
|
26
26
|
|
27
|
-
def timeout=
|
27
|
+
def timeout= time
|
28
28
|
end
|
29
29
|
|
30
|
-
def dir
|
30
|
+
def dir path, mask = "*"
|
31
31
|
r_mask = mask.gsub('.', '\.').gsub('*', '[^\/]')
|
32
32
|
|
33
33
|
Dir["#{path}/#{mask}"].map do |item|
|
@@ -35,6 +35,14 @@ module Backup
|
|
35
35
|
match[1] if match
|
36
36
|
end.compact.uniq
|
37
37
|
end
|
38
|
+
|
39
|
+
def delete_file path
|
40
|
+
FileUtils.rm path
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_dir directory
|
44
|
+
FileUtils.remove_dir directory
|
45
|
+
end
|
38
46
|
end
|
39
47
|
end
|
40
|
-
end
|
48
|
+
end
|
data/lib/backup/jar.rb
CHANGED
@@ -12,7 +12,7 @@ module Backup
|
|
12
12
|
Digest::MD5.hexdigest(@local_path)
|
13
13
|
end
|
14
14
|
|
15
|
-
def save increment = false, compression = nil
|
15
|
+
def save increment = false, compression = nil, purge = false
|
16
16
|
@meta_index = {}
|
17
17
|
@local_files = hash_local_files
|
18
18
|
|
@@ -118,9 +118,20 @@ module Backup
|
|
118
118
|
"#{meta_jar_path}/#{@timestamp}.yml",
|
119
119
|
@meta_index.to_yaml
|
120
120
|
)
|
121
|
-
end
|
122
121
|
|
123
|
-
|
122
|
+
pbar.finish
|
123
|
+
|
124
|
+
if purge
|
125
|
+
puts "Removing previous backups..."
|
126
|
+
previous_versions = Jar.jar_versions @file_item, @root_path, jar_hash, true
|
127
|
+
previous_versions.delete @timestamp
|
128
|
+
|
129
|
+
previous_versions.each do |version|
|
130
|
+
@file_item.delete_file "#{meta_jar_path}/#{version}.yml"
|
131
|
+
@file_item.delete_dir "#{@root_path}/#{jar_hash}/#{version}"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
124
135
|
end
|
125
136
|
|
126
137
|
def hash_local_files
|
data/lib/backup.rb
CHANGED
@@ -27,26 +27,26 @@ module Backup
|
|
27
27
|
@compression = Archive.new type.to_sym
|
28
28
|
end
|
29
29
|
|
30
|
-
def hostname=
|
30
|
+
def hostname= host
|
31
31
|
@hostname = host
|
32
32
|
@root_path = "#{@_root_path}/#{@hostname}"
|
33
33
|
end
|
34
34
|
|
35
|
-
def rsa_key
|
35
|
+
def rsa_key path, size
|
36
36
|
@key = Crypto::Key.from_file(path, size)
|
37
37
|
end
|
38
38
|
|
39
|
-
def create!
|
40
|
-
jar = Jar.new
|
41
|
-
jar.save
|
39
|
+
def create! local_path, increment = false, purge_previous = false
|
40
|
+
jar = Jar.new @file_item, @root_path, local_path, @key
|
41
|
+
jar.save increment, @compression, purge_previous
|
42
42
|
end
|
43
43
|
|
44
44
|
def jars
|
45
|
-
Jar.all
|
45
|
+
Jar.all @file_item, @root_path
|
46
46
|
end
|
47
47
|
|
48
|
-
def jar_versions
|
49
|
-
Jar.jar_versions
|
48
|
+
def jar_versions jar
|
49
|
+
Jar.jar_versions @file_item, @root_path, jar, !!jar[/^[0-9a-z]{32}$/]
|
50
50
|
end
|
51
51
|
|
52
52
|
def restore_jar_to(hash, timestamp, to)
|
data/lib/encbsconfig.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class EncbsConfig
|
2
2
|
attr_reader :paths, :bucket, :colorize, :compression, :hostname, :increment,
|
3
|
-
:key, :secret, :size, :token, :timeout, :verbose
|
3
|
+
:key, :purge, :secret, :size, :token, :timeout, :verbose
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@paths = ""
|
@@ -62,4 +62,8 @@ class EncbsConfig
|
|
62
62
|
def set_timeout attr
|
63
63
|
@timeout = attr
|
64
64
|
end
|
65
|
+
|
66
|
+
def purge!
|
67
|
+
@purge = true unless @increment
|
68
|
+
end
|
65
69
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: encbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 6
|
5
|
-
version: 0.2.1.
|
5
|
+
version: 0.2.1.beta1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Timothy Klim
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-24 00:00:00 +04:00
|
14
14
|
default_executable: encbs
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -151,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
151
|
requirements:
|
152
152
|
- - ">="
|
153
153
|
- !ruby/object:Gem::Version
|
154
|
-
hash:
|
154
|
+
hash: 3992220995732622958
|
155
155
|
segments:
|
156
156
|
- 0
|
157
157
|
version: "0"
|