diff options
Diffstat (limited to 'modules/tick/files/plugins/tarsnap')
-rw-r--r-- | modules/tick/files/plugins/tarsnap | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/modules/tick/files/plugins/tarsnap b/modules/tick/files/plugins/tarsnap new file mode 100644 index 0000000..0352cdb --- /dev/null +++ b/modules/tick/files/plugins/tarsnap @@ -0,0 +1,64 @@ +#!/usr/bin/env ruby + +require 'date' + +def parse_archive(archive) + # tozt-daily-2018-12-31_03:34:13-homedoypass + m = archive.match(/ + \A + (?<host>[a-z]+) # tozt + - + (?<period>[a-z]+) # daily + - + (?<year>[0-9]+) # 2018 + - + (?<month>[0-9]+) # 12 + - + (?<day>[0-9]+) # 31 + _ + (?<hour>[0-9]+) # 03 + : + (?<minute>[0-9]+) # 34 + : + (?<second>[0-9]+) # 13 + - + (?<name>[a-z_]+) # homedoypass + \z + /x) + raise "failed to parse archive name '#{archive}'" if m.nil? + + parsed = m.names.zip(m.captures).to_h + parsed["time"] = Time.new( + m["year"], + m["month"], + m["day"], + m["hour"], + m["minute"], + m["second"] + ) + parsed +end + +archives = %x(sudo tarsnap --list-archives) + .lines + .map(&:chomp) + .map{|s| parse_archive(s)} + +now = Time.now +most_recent_since = {} +archives.each do |archive| + name = archive["name"] + since = now - archive["time"] + + if most_recent_since[name].nil? || since < most_recent_since[name] + most_recent_since[name] = since + end +end + +stats = %x(sudo tarsnap --print-stats) +bytes = stats.chomp.match(/(\d+)\z/).to_s.to_i + +most_recent_since.sort.each do |name, since| + puts "tarsnap,name=#{name} days_since_last_run=#{since.to_f / 60.0 / 60.0 / 24.0}" +end +puts "tarsnap file_size=#{bytes}i" |