Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

For a pool with multiple file systems

zfs list -H -r -d 1 -t snapshot -o name nameoffilesystematroot | xargs -n1 zfs holds -H -r

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:

macbookpro08-centrim:~ gjp22$ zfs list -H -r -d 1 -t snapshot -o name gjp22 | xargs zfs holds -r
load: 4.94  cmd: zfs 39152 running 17.80u 112.52s
load: 3.73  cmd: zfs 39152 running 55.01u 349.29s
load: 3.15  cmd: zfs 39152 running 167.48u 1061.47s
load: 4.59  cmd: zfs 39152 running 267.57u 1697.49s
load: 5.19  cmd: zfs 39152 running 372.19u 2355.99s
load: 5.29  cmd: zfs 39152 running 432.89u 2736.79s

Borrowing from the other answer, with attention to the child file system alone:

macbookpro08-centrim:~ gjp22$ zfs list -H -r -d 1 -t snapshot -o name gjp22/intrigue | xargs zfs holds
NAME                              TAG  TIMESTAMP
macbookpro08-centrim:~ gjp22$ 

– and that output is almost immediate.

ZFS here is ZEVO Community Edition 1.1.1.

share|improve this answer

For a pool with a single file system

zfs list -H -r -d 1 -t snapshot -o name nameoffilesystem | xargs zfs holds

– 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:

macbookpro08-centrim:~ gjp22$ zfs list -H -r -d 1 -t snapshot -o name gjp22 | xargs zfs holds
load: 4.82  cmd: zfs 43038 running 0.59u 3.28s
NAME                     TAG                                           TIMESTAMP
gjp22@2012-10-28-212255  problem with LocalStorage for WOT for Safari  Mon Oct 29  6:44 2012
gjp22@2012-12-08-081957  experiment                                    Sat Dec  8  9:04 2012

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:

zfs list -H -r -d 1 -t snapshot -o name "tall/backups/zhandy/Pocket Time Machine" | xargs zfs holds

zfs list -H -r -d 1 -t snapshot -o name tall/backups/zhandy/Pocket\ Time\ Machine | xargs zfs holds

Output:

'tall/backups/zhandy/Pocket' is not a snapshot
'Time' is not a snapshot
cannot open 'tall/backups/zhandy/Pocket': dataset does not exist
cannot open 'Time': dataset does not exist
cannot open 'Machine@2012-09-18-210251': dataset does not exist
cannot open 'tall/backups/zhandy/Pocket': dataset does not exist
cannot open 'Time': dataset does not exist
cannot open 'Machine@2012-09-23-0330': dataset does not exist

… 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.

share|improve this answer
    
Discussion of this question and its current answers in The Comms Room: chat.stackexchange.com/transcript/message/7189404#7189404 –  Graham Perrin Dec 8 '12 at 16:28
    

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.