The Sourcerer's Apprentice

The adventures of David Heinemann in IT & software development

tarstat.pl

| Comments

Update: Maybe I shouldn’t be reading man pages at 1am, because this script is redundant. Colin Percival, the creator of Tarsnap pointed out in the comments below that one can simply use ’-f *’ to automatically specify all archives when using –print-stats.

I just wrote a small Perl script to print the stats of all my Tarsnap archives. Tarsnap doesn’t seem to have an option to do this easily, so this script builds a command in the format of tarsnap –print-stats –humanize-numbers -f archive1 -f archive2 … -f archiveN.

Sample output:

1
2
3
4
5
6
7
8
[david@Fnord ~]$ tarstats.pl
                                       Total size  Compressed size
All archives                                45 MB            38 MB
  (unique data)                             45 MB            37 MB
code-2011-08-19                             20 MB            15 MB
  (unique data)                             20 MB            15 MB
backups-2011-08-20                          25 MB            22 MB
  (unique data)                             25 MB            22 MB

The script:

1
2
3
4
5
6
7
8
9
#!/usr/bin/perl
my @archiveList = `tarsnap --list-archives`;
my $archiveString = "";
while (@archiveList)
{
    $archiveString .= " -f " .shift(@archiveList);
    chomp($archiveString);
}
print(`tarsnap --print-stats --humanize-numbers $archiveString`);

I probably should rewrite it in Shell, but it’s nearly 1am and I don’t feel like spending more than five minutes on this.

Script source is available on Pastebin.

Comments