niky81-s3rbackup 0.2.4 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -0
- data/bin/s3rbackup.rb +6 -1
- data/lib/s3dbsync.rb +34 -7
- metadata +2 -2
data/README
CHANGED
@@ -8,6 +8,7 @@ It's a backup system based on amazon s3 backend.
|
|
8
8
|
saved and retrived from S3.
|
9
9
|
* Query to database for file searching.
|
10
10
|
* Multiple database at one time
|
11
|
+
* Multiple compression type (see doc/stats.txt for speed results) selectable from config or command line
|
11
12
|
|
12
13
|
- Install
|
13
14
|
sudo gem install niky81-s3rbackup -s http://gems.github.com
|
data/bin/s3rbackup.rb
CHANGED
@@ -44,10 +44,14 @@ class OptS3rbackup
|
|
44
44
|
options[:log] = false
|
45
45
|
end
|
46
46
|
|
47
|
-
opts.on("--bucket-log", String, "Bucket log NAME") do |name|
|
47
|
+
opts.on("--bucket-log NAME", String, "Bucket log NAME") do |name|
|
48
48
|
options[:bucket_log] = name
|
49
49
|
end
|
50
50
|
|
51
|
+
opts.on("-p", "--compression [bz2|lzma|7z|gz]", String, "Compression type (always at maximum compression)") do |name|
|
52
|
+
options[:compression] = name
|
53
|
+
end
|
54
|
+
|
51
55
|
opts.on("-u", "--config-number NUM", Integer, "Number of config to use if nil use first") do |name|
|
52
56
|
options[:config_num] = name
|
53
57
|
end
|
@@ -71,6 +75,7 @@ config = Configure.new(options[:file_cfg], options[:config_num])
|
|
71
75
|
config.current["bucket"] = options[:bucket] if options[:bucket]
|
72
76
|
config.current["log"] = options[:log] if options[:log] != nil
|
73
77
|
config.current["bucket_log"] = options[:bucket_log] if options[:bucket_log]
|
78
|
+
config.current["compression"] = options[:compression] if options[:compression]
|
74
79
|
s3db = S3SyncDb.new(config.current)
|
75
80
|
s3db.bak(ARGV, options[:name], options[:descr])
|
76
81
|
s3db.salva_db
|
data/lib/s3dbsync.rb
CHANGED
@@ -123,7 +123,21 @@ class S3SyncDb
|
|
123
123
|
name = dirs[0] if !name
|
124
124
|
tf = Tempfile.new("s3rbackup")
|
125
125
|
tf_l = Tempfile.new("s3rbackup-listfile")
|
126
|
-
|
126
|
+
case @config["compression"]
|
127
|
+
when '7z'
|
128
|
+
tar = `tar -cv #{dirs.join(" ")} 2>#{tf_l.path} | 7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on -si #{tf.path}.7z`
|
129
|
+
file_path = "#{tf.path}.7z"
|
130
|
+
when 'lzma'
|
131
|
+
tar = `tar -cv #{dirs.join(" ")} 2>#{tf_l.path} | lzma -9 > #{tf.path}`
|
132
|
+
file_path = tf.path
|
133
|
+
when 'gz'
|
134
|
+
tar = `tar -cv #{dirs.join(" ")} 2>#{tf_l.path} | gzip -9 > #{tf.path}`
|
135
|
+
file_path = tf.path
|
136
|
+
else
|
137
|
+
tar = `tar -cv #{dirs.join(" ")} 2>#{tf_l.path} | bzip2 -9 > #{tf.path}`
|
138
|
+
file_path = tf.path
|
139
|
+
end
|
140
|
+
#FIXME delete file_path
|
127
141
|
|
128
142
|
filez = []
|
129
143
|
File.open(tf_l.path, 'r').each_line do |fh|
|
@@ -138,8 +152,8 @@ class S3SyncDb
|
|
138
152
|
doc["description"] = descr
|
139
153
|
doc["host"] = `hostname`.gsub("\n","").to_s
|
140
154
|
doc["user"] = `whoami`.gsub("\n","").to_s
|
141
|
-
doc["size"] = File.size(
|
142
|
-
doc["compression"] = "
|
155
|
+
doc["size"] = File.size(file_path)
|
156
|
+
doc["compression"] = @config["compression"]
|
143
157
|
doc["archive"] = "tar"
|
144
158
|
doc["files"] = filez.join("")
|
145
159
|
@db << doc
|
@@ -164,7 +178,7 @@ class S3SyncDb
|
|
164
178
|
# options["x-amz-meta-mtime"] = fstat.mtime.getutc.to_i if @save_time
|
165
179
|
# options["x-amz-meta-size"] = fstat.size if @save_size
|
166
180
|
|
167
|
-
store = S3Object.store(aws_name, open(
|
181
|
+
store = S3Object.store(aws_name, open(file_path), @config["bucket"], options)
|
168
182
|
obj = S3Object.find(aws_name, @config["bucket"])
|
169
183
|
#obj.store
|
170
184
|
obj.about.each do |key,val|
|
@@ -286,7 +300,7 @@ class S3SyncDb
|
|
286
300
|
def unpack(item, out_name = nil)
|
287
301
|
aws_name = item["aws_name"]
|
288
302
|
bucket = item["bucket"]
|
289
|
-
tf = Tempfile.new("s3runbackup")
|
303
|
+
tf = Tempfile.new("s3runbackup.#{item['archive']}.#{item['compression']}")
|
290
304
|
open(tf.path, 'w') do |file|
|
291
305
|
S3Object.stream(aws_name, bucket) do |chunk|
|
292
306
|
file.write chunk
|
@@ -294,10 +308,20 @@ class S3SyncDb
|
|
294
308
|
end
|
295
309
|
if out_name
|
296
310
|
`mkdir -p #{out_name}`
|
297
|
-
|
311
|
+
out_tar = "--directory #{out_name}"
|
298
312
|
else
|
299
|
-
|
313
|
+
out_tar = ""
|
300
314
|
end
|
315
|
+
case item["compression"]
|
316
|
+
when '7z'
|
317
|
+
tar = `7za x -so #{tf.path} | tar #{out_tar} -xf -`
|
318
|
+
when 'lzma'
|
319
|
+
tar = `cat #{tf.path} | lzma -d -c | tar #{out_tar} xf -`
|
320
|
+
when 'gz'
|
321
|
+
tar = `tar #{out_tar} -xzf #{tf.path}`
|
322
|
+
when 'bz2'
|
323
|
+
tar = `tar #{out_tar} -xjf #{tf.path}`
|
324
|
+
end
|
301
325
|
end
|
302
326
|
|
303
327
|
def delete(item)
|
@@ -319,5 +343,8 @@ class Configure
|
|
319
343
|
if @current.class.to_s == "Array"
|
320
344
|
@current = @current[config_num]
|
321
345
|
end
|
346
|
+
if !@current["compression"]
|
347
|
+
@current["compression"] = "bz2"
|
348
|
+
end
|
322
349
|
end
|
323
350
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niky81-s3rbackup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicola Sacchi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-06-
|
12
|
+
date: 2008-06-20 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|