Wrote some ruby scripts to help with restore
[backups/.git] / scripts / list-dates.rb
index b8a5c5099efc057853c162dc0fe61a032e14190d..18cdef98418ccae7b6cd6bf4fcef24a2de738924 100755 (executable)
@@ -1,14 +1,17 @@
 #!/usr/bin/ruby
 
+# Make sure the record separator is zero rather than new-line
+$/ = "\0"
+
+# Create a set of backup dates
 require 'set'
+dates = SortedSet.new
 
-dates = Set.new
+# Split each input record into 8 fields on spaces and grab the 7th as integer
+date_array = ARGF.map { |rec| rec.split( ' ', 8 )[6].to_i }
 
-ARGF.each( "\0" ) do |line|
-  fields = line.split ' ', 8
-  dates.add fields[6]
-end
+# Merge the dates into the set
+dates.merge date_array
 
-dates.each do |date|
-  puts date
-end
+# Output the sorted set
+puts dates.to_a