Last active
December 28, 2015 18:49
-
-
Save ilovezfs/7546204 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env perl | |
use Modern::Perl; | |
foreach my $fs (@ARGV) { | |
my ($refcount, @refs, %holds); | |
# get a hash of all subsidiary datasets with references | |
say "Looking up userrefs for $fs..."; | |
@refs = qx(zfs get -H -r userrefs $fs) | |
or die "$~\n$^E\n"; | |
foreach my $line (@refs) { | |
next unless $line =~ m/ | |
(\S+) | |
\s+ | |
userrefs | |
\s+ | |
(\d+) | |
/igx; | |
unless ($2) { | |
say "clean: $1"; | |
next; | |
} | |
else { | |
say "dirty: $1"; | |
$holds{$1} = $2; | |
} | |
} | |
say "DONE\n"; | |
say "Releasing holds..."; | |
foreach my $dataset (keys %holds) { | |
# prune holds recursively | |
my @tags = qx(zfs holds -H -r $dataset) | |
or die "$!\n$^E\n"; | |
foreach my $line (@tags) { | |
next unless $line =~ m/ | |
(\S+) # dataset - could be different for a subsidiary | |
\s+ | |
(\.send-\S+) # only prune tags left by `zfs send` | |
/igx; | |
my ($snapshot, $tag) = ($1, $2); | |
print "Releasing $snapshot from $tag..."; | |
qx(zfs release -r $tag $snapshot); | |
or die "$!\n$^E\n"; | |
say "ok" | |
} | |
} | |
say "DONE\n"; | |
} | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment