Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set timestamps of .zfs/snapshot/* directories to allow easy sorting #15110

Closed
jefft opened this issue Jul 26, 2023 · 2 comments
Closed

Set timestamps of .zfs/snapshot/* directories to allow easy sorting #15110

jefft opened this issue Jul 26, 2023 · 2 comments
Labels
Type: Feature Feature request or new feature

Comments

@jefft
Copy link

jefft commented Jul 26, 2023

Describe the feature would like to see added to OpenZFS

In a .zfs/snapshot directory, it would be useful if snapshot subdirectories had their mtime attribute set to the snapshot creation timestamp.

How will this feature improve OpenZFS?

If mtime were set, then with ls -l one could quickly see snapshot timestamps. "When was this snapshot created" is the most important fact about a snapshot. When I need to restore, I generally want to restore the newest snapshot. When I'm running out of disk space, I want to destroy the oldest snapshot. I'd like to use ls -l to see and sort by timestamp, rather than zfs list -t snapshot -s creation -o name <fs>.

Additional context

Currently (e.g zfs 2.1.5) the snapshot directory timestamps are not set usefully. E.g. here are the directory's timestamps for a recently created snapshot. None of them equal the snapshot's 'creation' property:

root@server /var/lib/postgresql/12/main/.zfs/snapshot # stat autosnap_2023-07-26_09:00:13_hourly
  File: autosnap_2023-07-26_09:00:13_hourly
  Size: 23              Blocks: 17         IO Block: 1536   directory
Device: b3h/179d        Inode: 281474976611565  Links: 19
Access: (0700/drwx------)  Uid: (  114/postgres)   Gid: (  120/ postgres)
Access: 2023-06-20 05:12:10.393136304 -0700
Modify: 2023-04-23 22:08:07.119052048 -0700
Change: 2023-04-23 22:08:07.119052048 -0700
 Birth: 2022-07-06 07:51:09.067191634 -0700
root@server /var/lib/postgresql/12/main/.zfs/snapshot # zfs get creation tank/var/lib/postgresql/12/main@autosnap_2023-07-26_09:00:13_hourly
NAME                                                                 PROPERTY  VALUE                  SOURCE
tank/var/lib/postgresql/12/main@autosnap_2023-07-26_09:00:13_hourly  creation  Wed Jul 26  2:00 2023  -
root@server /var/lib/postgresql/12/main/.zfs/snapshot # date
Wed Jul 26 02:59:54 PDT 2023
@jefft jefft added the Type: Feature Feature request or new feature label Jul 26, 2023
@nabijaczleweli
Copy link
Contributor

easy enough, I s'pose

# zfs get creation -rtsnap zest/CDs
NAME                                   PROPERTY  VALUE                  SOURCE
zest/CDs@initial-backup                creation  Tue Feb  2 20:14 2021  -
zest/CDs@blue-first-half               creation  Tue Feb  9 22:52 2021  -
zest/CDs@blue-second-half              creation  Wed Feb 10 19:04 2021  -
zest/CDs@final-whiskas                 creation  Thu Feb 11 17:40 2021  -
zest/CDs@reportaz-natalia-grygny-slad  creation  Fri Apr 16 19:19 2021  -
zest/CDs@gembird-usbirda               creation  Thu Aug  5 10:35 2021  -
zest/CDs@with-lg-driver                creation  Tue Aug 10 13:34 2021  -
zest/CDs@TIM2                          creation  Sun Oct 31 12:44 2021  -


$ ls -l /mnt/zest/CDs/.zfs/snapshot/
total 0
drwxrwxrwx 1 root root 0 Jul 27 03:07 blue-first-half
drwxrwxrwx 1 root root 0 Jul 27 03:07 blue-second-half
drwxrwxrwx 1 root root 0 Jul 27 03:07 final-whiskas
drwxrwxrwx 1 root root 0 Jul 27 03:07 gembird-usbirda
drwxrwxrwx 1 root root 0 Jul 27 03:07 initial-backup
drwxrwxrwx 1 root root 0 Jul 27 03:07 reportaz-natalia-grygny-slad
drwxrwxrwx 1 root root 0 Jul 27 03:07 TIM2
drwxrwxrwx 1 root root 0 Jul 27 03:07 with-lg-driver


# ls -l /mnt/zest/CDs/.zfs/snapshot/
[  159.993519] creation!!=1613065208 id=fffffffffd08
[  159.995784] creation!!=1635684276 id=ffffffffffb4
[  160.019590] creation!!=1628602452 id=fffffffffd8b
[  160.021570] creation!!=1612911125 id=ffffffffff29
[  160.023702] creation!!=1612296860 id=ffffffffffa8
[  160.037429] creation!!=1628159703 id=fffffffffe71
[  160.039569] creation!!=1618600749 id=ffffffffff61
[  160.052819] creation!!=1612983862 id=ffffffffff0e
total 0
drwxrwxrwx 1 root root 0 Oct 31  2021 TIM2
drwxrwxrwx 1 root root 0 Feb  9  2021 blue-first-half
drwxrwxrwx 1 root root 0 Feb 10  2021 blue-second-half
drwxrwxrwx 1 root root 0 Feb 11  2021 final-whiskas
drwxrwxrwx 1 root root 0 Aug  5  2021 gembird-usbirda
drwxrwxrwx 1 root root 0 Feb  2  2021 initial-backup
drwxrwxrwx 1 root root 0 Apr 16  2021 reportaz-natalia-grygny-slad
drwxrwxrwx 1 root root 0 Aug 10  2021 with-lg-driver

nabijaczleweli added a commit to nabijaczleweli/zfs that referenced this issue Jul 28, 2023
Closes: openzfs#15110
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
nabijaczleweli added a commit to nabijaczleweli/zfs that referenced this issue Jul 28, 2023
Closes: openzfs#15110
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
@nabijaczleweli
Copy link
Contributor

nabijaczleweli commented Jul 28, 2023

Try #15117 (this is probably easiest if you just curl https://github.com/openzfs/zfs/pull/15117.diff | patch -p1 in /var/lib/dkms/zfs/2.1.12/source (or whatever version you're using) and dkms unbuild/dkms install).

nabijaczleweli added a commit to nabijaczleweli/zfs that referenced this issue Jul 28, 2023
Closes: openzfs#15110
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
nabijaczleweli added a commit to nabijaczleweli/zfs that referenced this issue Jul 28, 2023
Closes: openzfs#15110
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
behlendorf pushed a commit to behlendorf/zfs that referenced this issue Aug 1, 2023
If looking up a snapdir inode failed, hold pool config – hold the 
snapshot – get its creation property – release it – release it, 
then use that as the [amc]time in the allocated inode. If that 
fails then fall back to current time. No performance impact since 
this is only done when allocating a new snapdir inode.
                                                       
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes openzfs#15110
Closes openzfs#15117
behlendorf pushed a commit that referenced this issue Aug 2, 2023
If looking up a snapdir inode failed, hold pool config – hold the 
snapshot – get its creation property – release it – release it, 
then use that as the [amc]time in the allocated inode. If that 
fails then fall back to current time. No performance impact since 
this is only done when allocating a new snapdir inode.
                                                       
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #15110
Closes #15117
lundman pushed a commit to openzfsonwindows/openzfs that referenced this issue Dec 12, 2023
If looking up a snapdir inode failed, hold pool config – hold the 
snapshot – get its creation property – release it – release it, 
then use that as the [amc]time in the allocated inode. If that 
fails then fall back to current time. No performance impact since 
this is only done when allocating a new snapdir inode.
                                                       
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes openzfs#15110
Closes openzfs#15117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Feature request or new feature
Projects
None yet
Development

No branches or pull requests

2 participants