/.zfs/ directory works differently on Linux - possible fix?
On linux, it seems that rather than a single .zfs directory, there's one per fs which list each filesystem's snapshots, so getting rid of expired snapshots doesn't work.
Rather than ls /.zfs/snapshot/, you could try the following:
# prune dbs if requested
if [ "x$maxnum" != x ]
then
zfs list -H -t snapshot -s creation -o name | grep ^$zpool\@$label_pfx- | awk "NR > $maxnum {print}" | while read snapname
do
zfs destroy -r $snapname || exit $?
done
fi
This works nicely on Ubuntu and I think it should work on BSD too, but obviously would benefit from a little testing!
Comments (4)
-
-
On Ubuntu 14.04 the /.zfs directory did not exits, but I found the snapshots listed under /[poolname]/.zfs/snapshot/, so I just change line 77 to be:
ls /$zpool/.zfs/snapshot/ ....
which seems to be a smaller change from the original code.
-
...but using ls will not work if the mount point is changed (mine is). The version using zfs list works wherever a pool or fs is mounted. And should also work across operating systems or if someone has set listsnapshots=off. It might be a bigger change, but is more robust.
-
Alternatively, you can replace
ls /.zfs/snapshot
with
ls
zfs get -H -o value mountpoint $zpool
/.zfs/snapshot/ - Log in to comment
Spotted a typo so signed up to comment - it should be "-S creation" with an uppercase S, not lowercase...