calculate age of snapshot in days
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 6 Jun 2009 13:21:07 +0000 (13:21 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 6 Jun 2009 13:21:07 +0000 (13:21 +0000)
git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@107 191e9f34-6774-4a6d-acfc-7664dacd4a2a

recepies/zfs/zfs-expire-snapshot.pl [new file with mode: 0755]

diff --git a/recepies/zfs/zfs-expire-snapshot.pl b/recepies/zfs/zfs-expire-snapshot.pl
new file mode 100755 (executable)
index 0000000..012fd19
--- /dev/null
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use DateTime;
+
+my $now = DateTime->now();
+
+open(my $fs, '-|', 'zfs list -H');
+while(<$fs>) {
+       chomp;
+       my ( $name, $used, $avail, $refer, $mountpoint ) = split(/\t/,$_,6);
+
+       next unless $name =~ m{@(\d\d\d\d)-(\d\d)-(\d\d)};
+
+       my $date = DateTime->new( year => $1, month => $2, day => $3 );
+       my $age = $now->delta_days( $date );
+
+       warn "$name $used $refer [", $age->delta_days, " days]\n";
+}