Skip to content

Instantly share code, notes, and snippets.

@ilovezfs
Last active December 28, 2015 18:49
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 ilovezfs/7546204 to your computer and use it in GitHub Desktop.
Save ilovezfs/7546204 to your computer and use it in GitHub Desktop.
#!/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