Skip to content

Instantly share code, notes, and snippets.

@nmarley
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmarley/c5c45eefa4998880937a to your computer and use it in GitHub Desktop.
Save nmarley/c5c45eefa4998880937a to your computer and use it in GitHub Desktop.
Analyse Tarsnap Usage
require 'open3'
require 'pp'
def get_stats(archive_name)
cmd = "sudo tarsnap --print-stats -f #{archive_name}"
stats = run_cmd(cmd)[3,4]
end
def get_uniq_comp_size(stats)
stats.last.split(/\s+/)[-1]
end
def get_archive_storj_size(archive_name)
stats = get_stats(archive_name)
size = get_uniq_comp_size(stats)
size
end
def run_cmd(cmd)
out = nil
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid
out = stdout.readlines
err = stderr.readlines
exit_status = wait_thr.value
end
out
end
list = File.read('sorted').split("\n")
list.each do |archive_name|
size = get_archive_storj_size(archive_name)
puts "#{archive_name}: #{size}\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment