Question
Already I can check each snapshot of a filesystem individually, manually.
I would prefer to check all at once (all with a single command or script). Please:
- can that be done with a script?
The answer should be good for file systems with a space within the name.
Background
From the man page for zfs(8):
zfs holds [-H] [-r] snapshot…
… -r
Specifies that a hold with the given tag is applied recursively to the snapshots of all descendent file systems.
I wondered whether recent snapshots are treated as descendants of an older snapshot. No:
Last login: Sat Dec 8 09:02:26 on ttys003
macbookpro08-centrim:~ gjp22$ zfs holds -r gjp22@2012-12-08-081957
NAME TAG TIMESTAMP
macbookpro08-centrim:~ gjp22$ zfs holds -r gjp22@2012-10-28-212255
NAME TAG TIMESTAMP
gjp22@2012-10-28-212255 problem with LocalStorage for WOT for Safari Mon Oct 29 6:44 2012
macbookpro08-centrim:~ gjp22$ zfs hold experiment gjp22@2012-12-08-081957
macbookpro08-centrim:~ gjp22$ zfs holds -r gjp22@2012-10-28-212255
NAME TAG TIMESTAMP
gjp22@2012-10-28-212255 problem with LocalStorage for WOT for Safari Mon Oct 29 6:44 2012
macbookpro08-centrim:~ gjp22$ zfs holds -r gjp22@2012-12-08-081957
NAME TAG TIMESTAMP
gjp22@2012-12-08-081957 experiment Sat Dec 8 9:04 2012
macbookpro08-centrim:~ gjp22$ zfs holds -r gjp22@2012-10-28-212255
NAME TAG TIMESTAMP
gjp22@2012-10-28-212255 problem with LocalStorage for WOT for Safari Mon Oct 29 6:44 2012
macbookpro08-centrim:~ gjp22$
Clarification
I do not plan to combine both checks and destruction in a single command or script. This question is essentially about the checks.
Not sure about how this looked back in 2012 but now you can check the
userrefs
property:To list all holds in all pools:
zfs get -Ht snapshot userrefs | grep -v $'\t'0 | cut -d $'\t' -f 1 | tr '\n' '\0' | xargs -0 zfs holds
For a pool with multiple file systems
Credit to calmh in
irc://irc.freenode.net/#zfs
but I'm not sure whether the syntax needs a little more work.For me, with a simple file system hierarchy (only one child) and relatively few snapshots (currently seventeen of the child), the command seems to not reach a conclusion. Example:
Borrowing from the other answer, with attention to the child file system alone:
– and that output is almost immediate.
ZFS here is ZEVO Community Edition 1.1.1.
For a pool with a single file system
– that is, without
-r
recursion to the right of the pipe.Credit to calmh in
irc://irc.freenode.net/#zfs
Working example
For a file system with no space in its name:
There was one Control-T to see how things were running.
For completeness, I should state that there is a child of
gjp22
. But I guess that this example (without attention to descendants) does prove the effectiveness of the command.Non-working examples
For a file system named
Pocket Time Machine
(spaces within its name), neither of the following commands succeeds:Output:
… and so on.
This is implicitly a question within an answer, sorry … someone with good command line knowledge (not me) might be able to smarten this answer without me spinning off to a separate question. I'll seek advice in chat.
The following command will show all snapshots of [pool] (<-replace this with your pool name) that have holds
the properties will be listed as
property:stuff
with that information we can free the snapshots..
(replace 'property:stuff' with whatever is holding your dataset)
..and finally delete them