niky81-s3rbackup 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/s3query.rb +9 -1
  2. data/lib/s3dbsync.rb +42 -11
  3. metadata +2 -2
data/bin/s3query.rb CHANGED
@@ -89,7 +89,15 @@ class OptS3rquery
89
89
  opts.on("--test", "Test something") do |name|
90
90
  options[:test] = true
91
91
  end
92
-
92
+
93
+ opts.on("--files", "Get files list") do |name|
94
+ options[:files] = true
95
+ end
96
+
97
+ opts.on("--inside", "Search inside files, only start_with") do |name|
98
+ options[:inside] = true
99
+ end
100
+
93
101
  opts.on_tail("-h", "--help", "Show this message") do
94
102
  puts opts
95
103
  exit
data/lib/s3dbsync.rb CHANGED
@@ -26,7 +26,11 @@ class S3SyncDb
26
26
 
27
27
  def initialize_db
28
28
  puts "Creating #{@domain_db} db..."
29
- @sdb.create_domain(@domain_db)
29
+ @sdb.create_domain(@domain_db)
30
+ if @config['files_db']
31
+ puts "Creating file db #{@config['files_db']} db..."
32
+ @sdb.create_domain(@config['files_db'])
33
+ end
30
34
  puts "Creating #{@bucket} bucket..."
31
35
  begin
32
36
  bbackup = Bucket.find(@bucket)
@@ -43,12 +47,16 @@ class S3SyncDb
43
47
  bucket1.delete(true)
44
48
  puts "Deleting db #{@domain_db}..."
45
49
  @sdb.delete_domain(@domain_db)
50
+ if @config['files_db']
51
+ puts "Deleting file db #{@config['files_db']} db..."
52
+ @sdb.delete_domain(@config['files_db'])
53
+ end
46
54
  end
47
55
 
48
56
  def test
49
57
  #buk = @s3.buckets
50
- buk = @s3.buckets.map{|b| b.name}
51
- puts "Buckets on S3: #{buk.join(', ')}"
58
+ #buk = @s3.buckets.map{|b| b.name}
59
+ #puts "Buckets on S3: #{buk.join(', ')}"
52
60
  end
53
61
 
54
62
  #s3 sdb
@@ -89,13 +97,25 @@ class S3SyncDb
89
97
  doc["size"] = File.size(file_path)
90
98
  doc["compression"] = @config["compression"]
91
99
  doc["archive"] = "tar"
92
- #doc["files"] = filez.join("")
93
100
  #@db << doc
94
101
  aws_name = "#{doc["name"]}##{`date +%Y%m%d_%H.%M.%S`}".gsub("\n","")
95
102
  doc["aws_name"] = aws_name
96
103
  @sdb.put_attributes @domain_db, aws_name, doc
97
- #TODO aggiungere md5
104
+ if @config['files_db']
105
+ #tutti in uno
106
+ filez_name = []
107
+ filez.each do |fil|
108
+ begin
109
+ filez_name << File.basename(fil.gsub("\n", ""))
110
+ rescue
111
+ end
112
+ end
113
+ @sdb.put_attributes @config['files_db'], aws_name, {
114
+ :files_full => filez.map {|t| t.gsub("\n","")},
115
+ :files_name => filez_name}
116
+ end
98
117
 
118
+ #TODO aggiungere md5
99
119
  # Store it!
100
120
  options = {}
101
121
  options["x-amz-meta-host"] = doc["host"]
@@ -107,11 +127,11 @@ class S3SyncDb
107
127
  options["x-amz-meta-archive"] = doc["archive"]
108
128
 
109
129
  store = S3Object.store(aws_name, open(file_path), @config["bucket"], options)
110
- obj = S3Object.find(aws_name, @config["bucket"])
130
+ #obj = S3Object.find(aws_name, @config["bucket"])
111
131
  #obj.store
112
- obj.about.each do |key,val|
113
- doc[key] = val
114
- end
132
+ #obj.about.each do |key,val|
133
+ # doc[key] = val
134
+ #end
115
135
  #TODO aggiungere check
116
136
  send_mail("S3rbackup - Saved #{doc["name"]}", (doc.to_a.map {|val| "#{val[0]}: #{val[1]}"}).join("\n") + "\n\nFiles:\n\t#{filez.join("\t")}")
117
137
  end
@@ -146,7 +166,12 @@ class S3SyncDb
146
166
  end
147
167
  if words_search.nitems == 1
148
168
  #ho solo una parola uso startwith sul nome
149
- search = "['aws_name' starts-with #{words_search[0]}] union ['description' starts-with #{words_search[0]}]"
169
+ if cmd_opt[:inside]
170
+ #cerco dentro ai file
171
+ search = "['files_full' starts-with #{words_search[0]}] union ['files_name' starts-with #{words_search[0]}]"
172
+ else
173
+ search = "['aws_name' starts-with #{words_search[0]}] union ['description' starts-with #{words_search[0]}]"
174
+ end
150
175
  elsif words_search.nitems == 0
151
176
  #devo caricare tutto
152
177
  search = "['datetime' > '\\'1970\\'']"
@@ -155,12 +180,18 @@ class S3SyncDb
155
180
  end
156
181
  #p search
157
182
  results = []
158
- @sdb.query(@domain_db, search) do |result|
183
+ @sdb.query(cmd_opt[:inside] ? @config['files_db'] : @domain_db, search) do |result|
159
184
  result[:items].each do |item|
160
185
  hattr = @sdb.get_attributes(@domain_db, item)[:attributes]
161
186
  hattr_ok = {}
162
187
  hattr.each do |key,val|
163
188
  hattr_ok[key] = val[0]
189
+ if cmd_opt[:files]
190
+ #per ogni file scrico la lista
191
+ hattr_ok_files ||= {}
192
+ hattr_ok_files[key] = @sdb.get_attributes(@config['files_db'], item)[:attributes]
193
+ p hattr_ok_files[key] #FIXME vedere come visualizzarli...
194
+ end
164
195
  end
165
196
  results << hattr_ok
166
197
  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.3.0
4
+ version: 0.3.1
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-09-26 00:00:00 -07:00
12
+ date: 2008-09-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency