openzfs / zfs

OpenZFS on Linux and FreeBSD
https://openzfs.github.io/openzfs-docs
Other
10.63k stars 1.75k forks source link

Request: Make ZFS snapshot directory timestamps the snapshot creation times #10690

Open helamonster opened 4 years ago

helamonster commented 4 years ago

System information

Type Version/Name
Distribution Name Ubuntu
Distribution Version 20.04
Linux Kernel 5.4.0-40-generic
Architecture x86_64
ZFS Version 0.8.3-1ubuntu12.2
SPL Version 0.8.3-1ubuntu12.2

Describe the problem you're observing

When listing the zfs snapshot directories for a mounted dataset, the timestamps do not appear to be of any useful value. Currently, the snapshot directory timestamps appear to be undefined (or maybe the first access time of the .zfs/snapshot directory since the dataset was last mounted?), or at least not based on snapshot creation times.

It would be nice if the zfs snapshot directory timestamps contained useful values, specifically and at least the snapshot creation time. The mtime value makes the most sense. I'm not sure how the atime or ctime could be used, but they could simply be set to the same value.

Describe how to reproduce the problem

Here's an example:

zfs list -r -t filesystem,snapshot  -o creation,name,mountpoint bpool/BOOT/ubuntu/HEAD

CREATION               NAME                                                          MOUNTPOINT
Fri Apr 24 11:43 2020  bpool/BOOT/ubuntu/HEAD                                        /boot
Thu Jul 23  3:39 2020  bpool/BOOT/ubuntu/HEAD@2020-07-23-03-39-10                    -

stat /boot/.zfs/snapshot/2020-07-23-03-39-10

  File: /boot/.zfs/snapshot/2020-07-23-03-39-10
  Size: 21              Blocks: 17         IO Block: 2560   directory
Device: 4bh/75d Inode: 281474976708482  Links: 5
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-04-08 22:11:57.746270664 -0400
Modify: 2020-07-08 01:55:23.616993836 -0400
Change: 2020-07-08 01:55:23.616993836 -0400
 Birth: -

How this change can be helpful

Generally, it would be nice to see the snapshot creation times when listing zfs snapshot directories (whether listing from a terminal or a file browser).

Also: I have some tools that list zfs snapshots in 1 of 2 ways:

  1. If the dataset is mounted, listing the zfs snapshot directory (much faster but can only get snapshot names, no other fields)
  2. Fallback to using zfs list (much slower)

I want to make some changes to my tools that require knowing both the snapshot creation times AND names. This effectively makes method 1 unusable so the second method must be used and is WAY slower.

DeHackEd commented 4 years ago

Issues with this request:

If you're willing to fall back to the zfs list method you might as well do it. Forcing the .zfs/snapshot directory to show modification times isn't going to be significantly faster.

helamonster commented 4 years ago

Hmm, if having this feature requires the same method of listing snapshot creation times that zfs list does, then this is definitely a no go. I'm wondering if there is a more optimal method that can be done. But if there were, I would imagine it would already have been implemented for zfs list.

Any other ideas?

For my tools, I may have to be creative and cache snapshot info in an sqlite database or something.

bghira commented 4 years ago

most people simply embed it into the name of the snapshot.

akorn commented 4 years ago

It's still annoying that you need relatively complex and verbose syntax to achieve what ls -rt does very succinctly.

Possible workaround: maybe write a zsnap_ls script that implements some of the more common switches of ls but lists the snapshots of the zfs instance(s) whose .snapshot directory it got passed on the command line.

Would anyone be interested in such a script?