<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -16,7 +16,7 @@ class OptS3rquery
 	def self.parse(args)
 		options = {}
 		opts = OptionParser.new do |opts|
-			opts.banner = &quot;Usage: s3query.rb [options] &lt;search|get|unpack|delete|stats&gt; &lt;parameters&gt; (parameters can be name=test or simply test)&quot;
+			opts.banner = &quot;Usage: s3query.rb [options] &lt;search|get|unpack|delete|stats|delete_older&gt; &lt;parameters&gt; (parameters can be name=test or simply test)&quot;
 		
 			opts.on(&quot;-s&quot;, &quot;search words&quot;, String, &quot;Search something&quot;) do |name|
 				options[:op] = &quot;search&quot;
@@ -78,6 +78,10 @@ class OptS3rquery
 				options[:config_num] = name
 			end
 			
+			opts.on(&quot;-e&quot;, &quot;--item-to-keep NUM&quot;, Integer, &quot;Number of item to keep after deleting the olders (delete_older)&quot;) do |name|
+				options[:delete_older] = name
+			end
+			
 			opts.on(&quot;--initialize&quot;, &quot;Inizializza bucket and db&quot;) do |name|
 				options[:initialize] = true
 			end
@@ -85,7 +89,7 @@ class OptS3rquery
 			opts.on(&quot;--destroy&quot;, &quot;Destroy bucket and db&quot;) do |name|
 				options[:destroy] = true
 			end
-
+			
 			opts.on(&quot;--test&quot;, &quot;Test something&quot;) do |name|
 				options[:test] = true
 			end
@@ -129,7 +133,7 @@ s3db = S3SyncDb.new(config.current)
 
 command = ARGV.shift
 case command
-	when /[search|get|unpack|delete|stats]/
+	when /[search|get|unpack|delete|stats|delete_older]/
 		results = s3db.find(ARGV, nil, options)
 		results = get_last(results) if options[:last]
 		results = get_first(results) if options[:first]
@@ -166,6 +170,27 @@ case command
 			puts &quot;Deleting of #{ret[&quot;aws_name&quot;]}&quot;
 			s3db.delete(ret)
 		end
+	when 'delete_older'
+		#cancella i piu' vecchi mantenendo options[:delete_older] item
+		# per ongi nome trovato
+		if options[:delete_older] == nil
+			options[:delete_older] = 2
+		end
+		group = {}
+		results.each do |ret|
+			group[ret[&quot;name&quot;]] ||= []
+			group[ret[&quot;name&quot;]] &lt;&lt; ret
+		end
+		group.each do |key, arr_ret|
+			arr_ret.sort! {|x,y| x[&quot;datetime&quot;] &lt;=&gt; y[&quot;datetime&quot;] }
+			options[:delete_older].times do |num|
+				arr_ret.pop
+			end 
+			arr_ret.each do |ret|
+				puts &quot;Deleting of #{ret[&quot;aws_name&quot;]}&quot;
+				s3db.delete(ret)
+			end
+		end
 	when 'stats'
 		#get size
 		bucks_s = {}</diff>
      <filename>bin/s3query.rb</filename>
    </modified>
    <modified>
      <diff>@@ -40,6 +40,10 @@ class OptS3rbackup
 				options[:log] = true
 			end
 		
+			opts.on(&quot;--md5&quot;, &quot;Check md5, upload only if md5 differ&quot;) do |name|
+				options[:md5_check] = true
+			end
+
 			opts.on(&quot;--nolog&quot;, &quot;Log disabled&quot;) do |name|
 				options[:log] = false
 			end
@@ -77,5 +81,5 @@ config.current[&quot;log&quot;] = options[:log] if options[:log] != nil
 config.current[&quot;bucket_log&quot;] = options[:bucket_log] if options[:bucket_log]
 config.current[&quot;compression&quot;] = options[:compression] if options[:compression]
 s3db = S3SyncDb.new(config.current)
-s3db.bak(ARGV,  options[:name],  options[:descr])
+s3db.bak(ARGV,  options[:name],  options[:descr], options[:md5_check])
 #s3db.salva_db</diff>
      <filename>bin/s3rbackup.rb</filename>
    </modified>
    <modified>
      <diff>@@ -60,7 +60,7 @@ class S3SyncDb
 	end
 
 	#s3 sdb
-	def bak(dirs, name, descr)
+	def bak(dirs, name, descr, md5_check = false)
 		name = dirs[0] if !name
 		tf = Tempfile.new(&quot;s3rbackup&quot;)
 		tf_l = Tempfile.new(&quot;s3rbackup-listfile&quot;)
@@ -95,45 +95,58 @@ class S3SyncDb
 		doc[&quot;host&quot;] = `hostname`.gsub(&quot;\n&quot;,&quot;&quot;).to_s
 		doc[&quot;user&quot;] = `whoami`.gsub(&quot;\n&quot;,&quot;&quot;).to_s
 		doc[&quot;size&quot;] = File.size(file_path)
+		doc[&quot;md5&quot;] = `md5sum #{file_path} | cut -d &quot; &quot; -f 1`.gsub(&quot;\n&quot;, &quot;&quot;)
 		doc[&quot;compression&quot;] = @config[&quot;compression&quot;]
 		doc[&quot;archive&quot;] = &quot;tar&quot;
 		#@db &lt;&lt; doc
 		aws_name = &quot;#{doc[&quot;name&quot;]}##{`date +%Y%m%d_%H.%M.%S`}&quot;.gsub(&quot;\n&quot;,&quot;&quot;)
 		doc[&quot;aws_name&quot;] = aws_name
-		@sdb.put_attributes @domain_db, aws_name, doc
-		if @config['files_db']
-			#tutti in uno
-			filez_name = []
-			filez.each do |fil|
-				begin
-					filez_name &lt;&lt; File.basename(fil.gsub(&quot;\n&quot;, &quot;&quot;))
-				rescue
+
+		carica = true
+		if md5_check
+			search = &quot;['md5' = '#{doc[&quot;md5&quot;]}']&quot;
+			@sdb.query(@domain_db, search) do |result|
+				result[:items].each do |item|
+					hattr = @sdb.get_attributes(@domain_db, item)[:attributes]
+					if hattr[&quot;name&quot;][0] == doc[&quot;name&quot;]
+						carica = false
+					end
 				end
 			end
-			@sdb.put_attributes @config['files_db'], aws_name, { 
-																:files_full =&gt; filez.map {|t| t.gsub(&quot;\n&quot;,&quot;&quot;)}, 
-																:files_name =&gt; filez_name}
 		end
-
-		#TODO aggiungere md5
-  # Store it!
-		options = {}
-		options[&quot;x-amz-meta-host&quot;] = doc[&quot;host&quot;]
-		options[&quot;x-amz-meta-user&quot;] = doc[&quot;user&quot;]
-		options[&quot;x-amz-meta-descrizione&quot;] = doc[&quot;description&quot;]
-		options[&quot;x-amz-meta-current_path&quot;] = doc[&quot;current_path&quot;]
-		options[&quot;x-amz-meta-size&quot;] = doc[&quot;size&quot;]
-		options[&quot;x-amz-meta-compression&quot;] = doc[&quot;compression&quot;]
-		options[&quot;x-amz-meta-archive&quot;] = doc[&quot;archive&quot;]
-
-		store = S3Object.store(aws_name, open(file_path), @config[&quot;bucket&quot;], options)
-		#obj = S3Object.find(aws_name, @config[&quot;bucket&quot;])
-		#obj.store
-		#obj.about.each do |key,val|
-		#	doc[key] = val
-		#end
-		#TODO aggiungere check
-		send_mail(&quot;S3rbackup - Saved #{doc[&quot;name&quot;]}&quot;, (doc.to_a.map {|val| &quot;#{val[0]}: #{val[1]}&quot;}).join(&quot;\n&quot;) + &quot;\n\nFiles:\n\t#{filez.join(&quot;\t&quot;)}&quot;)
+		if carica 
+			@sdb.put_attributes @domain_db, aws_name, doc
+			if @config['files_db']
+				#tutti in uno
+				filez_name = []
+				filez.each do |fil|
+					begin
+						filez_name &lt;&lt; File.basename(fil.gsub(&quot;\n&quot;, &quot;&quot;))
+					rescue
+					end
+				end
+				@sdb.put_attributes @config['files_db'], aws_name, { 
+																	:files_full =&gt; filez.map {|t| t.gsub(&quot;\n&quot;,&quot;&quot;)}, 
+																	:files_name =&gt; filez_name}
+			end
+	
+			#TODO aggiungere md5
+	  # Store it!
+			options = {}
+	#		options[&quot;x-amz-meta-host&quot;] = doc[&quot;host&quot;]
+	#		options[&quot;x-amz-meta-user&quot;] = doc[&quot;user&quot;]
+	#		options[&quot;x-amz-meta-descrizione&quot;] = doc[&quot;description&quot;]
+	#		options[&quot;x-amz-meta-current_path&quot;] = doc[&quot;current_path&quot;]
+	#		options[&quot;x-amz-meta-size&quot;] = doc[&quot;size&quot;]
+	#		options[&quot;x-amz-meta-compression&quot;] = doc[&quot;compression&quot;]
+	#		options[&quot;x-amz-meta-archive&quot;] = doc[&quot;archive&quot;]
+	
+			store = S3Object.store(aws_name, open(file_path), @config[&quot;bucket&quot;], options)
+			#TODO aggiungere check
+			send_mail(&quot;S3rbackup - Saved #{doc[&quot;name&quot;]}&quot;, (doc.to_a.map {|val| &quot;#{val[0]}: #{val[1]}&quot;}).join(&quot;\n&quot;) + &quot;\n\nFiles:\n\t#{filez.join(&quot;\t&quot;)}&quot;)
+		else
+			send_mail(&quot;S3rbackup - Not Saved #{doc[&quot;name&quot;]} - md5 already exist&quot;, (doc.to_a.map {|val| &quot;#{val[0]}: #{val[1]}&quot;}).join(&quot;\n&quot;) + &quot;\n\nFiles:\n\t#{filez.join(&quot;\t&quot;)}&quot;)
+		end
 	end
 
 	def find(words, bucket = nil, cmd_opt = {})</diff>
      <filename>lib/s3dbsync.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 Gem::Specification.new do |s|
   s.name = &quot;s3rbackup&quot;
-  s.version = &quot;0.3.4&quot;
-  s.date = &quot;2008-09-28&quot;
+  s.version = &quot;0.4.0&quot;
+  s.date = &quot;2008-11-28&quot;
   s.summary = &quot;Simple backup on Amazon S3&quot;
   s.email = &quot;sacchi.nicola@gmail.com&quot;
   s.homepage = &quot;http://github.com/niky81/s3rbackup&quot;</diff>
      <filename>s3rbackup.gemspec</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7fc2b7805445bf8bb84fa401bb91e27b46179639</id>
    </parent>
  </parents>
  <author>
    <name>nik</name>
    <email>sacchi.nicola@gmail.com</email>
  </author>
  <url>http://github.com/niky81/s3rbackup/commit/343095aa18ccb198b1d46254b37f43be02312851</url>
  <id>343095aa18ccb198b1d46254b37f43be02312851</id>
  <committed-date>2008-11-28T11:20:51-08:00</committed-date>
  <authored-date>2008-11-28T11:20:51-08:00</authored-date>
  <message>added md5 check and delete_older</message>
  <tree>9a54235a3eca641d2172d38208c535f2bf22a3e1</tree>
  <committer>
    <name>nik</name>
    <email>sacchi.nicola@gmail.com</email>
  </committer>
</commit>
