Last active
August 29, 2015 14:20
-
-
Save nmarley/c5c45eefa4998880937a to your computer and use it in GitHub Desktop.
Analyse Tarsnap Usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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