kimono-koans / httm

Interactive, file-level Time Machine-like tool for ZFS/btrfs/nilfs2 (and even Time Machine and Restic backups!)
https://crates.io/crates/httm
Mozilla Public License 2.0
1.33k stars 28 forks source link

Snapshots not detected with btrfs #39

Closed KodyVB closed 2 years ago

KodyVB commented 2 years ago

Problem: Existing snapshots are not being detected when commands like doas httm -i ~/ are used when snapshots are under /mnt/rpool/snapshots/home, where /mnt/rpool is the root.

Steps to reproduce:

  1. Have the root mounted under a directory, such as /mnt/rpool with something like this in /etc/fstab (may have to restart computer instead of just using doas mount -a after adding to /etc/fstab)
    UUID=...    /mnt/rpool  btrfs       ...,subvolid=5,subvol=/ 0 0
  2. Create a directory to hold the snapshots, i.e. doas mkdir -p /mnt/rpool/snapshots/home
  3. Create a snapshot of the home subvolume (assuming /home is a subvolume), doas btrfs subvolume snapshot -r /home /mnt/rpool/snapshots/home/@home.test
  4. Run doas httm -i ~/

Expected results: Snapshot under /mnt/rpool/snapshots/home/@home.test appears as an option.

Actual results: Snapshot doesn't appear as an option.

Additional information: The (trimmed down) results of doas btrfs subvolume list -s / are:

ID 3005 gen 594605 cgen 198847 top level 5 otime 2021-10-31 12:19:14 path @
ID 7309 gen 591271 cgen 466749 top level 5 otime 2022-04-03 05:50:56 path snapshots/home/@home.20220403T0550
ID 8040 gen 591271 cgen 521624 top level 5 otime 2022-05-01 00:00:01 path snapshots/home/@home.20220501T0000
ID 8041 gen 591271 cgen 521690 top level 5 otime 2022-05-01 00:32:41 path snapshots/root/@.20220501T0032
ID 8208 gen 594637 cgen 535944 top level 259 otime 2022-05-08 19:54:17 path @home/kody/.local/share/Steam
...
ID 9017 gen 592987 cgen 592986 top level 5 otime 2022-06-07 21:40:26 path snapshots/root/@.20220607T2140
ID 9018 gen 592988 cgen 592987 top level 5 otime 2022-06-07 21:40:26 path snapshots/root/@.20220607T2140_1
...
ID 9038 gen 594602 cgen 594602 top level 5 otime 2022-06-08 20:00:01 path snapshots/home/@home.20220608T2000
kimono-koans commented 2 years ago

Could you send the output of btrfs subvolume snapshot -s /home?

Does the subvol with snapshots perhaps need to mounted at that location? That is -- is it showing up in this list but it is not actually mounted (snapshots aren't auto-mounted)? Whereas when I mount /mnt all attached/children subvols like /mnt/.snapshots come along for the ride?

KodyVB commented 2 years ago

@kimono-koans I get the same output when I run btrfs subvolume snapshot -s /home as I do when I run btrfs subvolume snapshot -s / except "@home/kody/.local/share/Steam" becomes "kody/.local/share/Steam"

I tried the following:

  1. Create top level 5 snapshot directory with doas btrfs subvolume create /mnt/rpool/snapshot
  2. doas mkdir -v /mnt/rpool/snapshot/home
  3. doas btrfs subvolume snapshot -r /home /mnt/rpool/snapshot/home/test
  4. doas mkdir /home/test
  5. doas mount -o subvol=snapshot /dev/sda2 /home/test
  6. doas httm -i ~/

And I did not see the snapshot.

However, if I did:

  1. doas mkdir /home/test_second
  2. doas btrfs subvolume snapshot -r /home /home/test_second/test
  3. doas httm -i ~/

Then, I saw the snapshot from /home/test_second/test

kimono-koans commented 2 years ago

Strange, I can make your test case work with the latest bits and using sudo. I'm sure I'm missing something. What am I missing?

─────────────────────────────────────────────────────────────────────
Thu Jun  9 16:17:55 2022   0 bytes  "/mnt/home/snapshots1/test"
Thu Jun  9 16:19:44 2022   8 bytes  "/mnt/.snapshots/26/snapshot/test"
Thu Jun  9 16:20:23 2022  16 bytes  "/mnt/@home/1/test"
Thu Jun  9 16:26:58 2022  25 bytes  "/mnt/@home/2/test"
─────────────────────────────────────────────────────────────────────
Thu Jun  9 16:26:58 2022  25 bytes  "/mnt/test"
─────────────────────────────────────────────────────────────────────
KodyVB commented 2 years ago

I'm not sure what's missing. How does the program know where to look for the snapshots? Does it use the ID of the target and the top level of the snapshot or something?

kimono-koans commented 2 years ago

How does the program know where to look for the snapshots? Does it use the ID of the target and the top level of the snapshot or something?

It parses /proc/mounts/ for the dataset mountpoint, then joins to the relative snapshot paths supplied by btrfs sub list -s.

Perhaps it should join the subvol= location to your path? So, for instance, you have partitioned your drive instead of dividing one partition into subvols, so you have something like a subvol=/@ and a subvol=/@home but they all show as mounted to one location like /mnt

Or is it that /proc/mounts/ is lying? It says you're mounted at /mnt/rpool but you're really mounted at /? And you chroot or by some other magic you're delivered into the environment?

KodyVB commented 2 years ago

Just for clarity to make sure we're on the same page, this is my /etc/fstab:

# /dev/sda2
UUID=<UUID> /           btrfs       rw,noatime,compress=zstd:3,ssd,discard=async,space_cache,subvolid=256,subvol=/@ 0 0

# /dev/sda1
UUID=<UUID>     /boot/EFI   vfat        rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro   0 2

# /dev/sda2
UUID=<UUID> /home       btrfs       rw,noatime,compress=zstd:3,ssd,discard=async,space_cache,subvolid=259,subvol=/@home 0 0
UUID=<UUID> /var/log    btrfs       rw,noatime,compress=zstd:3,ssd,discard=async,space_cache,subvolid=260,subvol=/@var_log  0 0
UUID=<UUID> /mnt/rpool  btrfs       rw,noatime,compress=zstd:3,ssd,discard=async,space_cache,subvolid=5,subvol=/    0 0

I'm not chrooting into it - it boots up with everything like normal, except you can:

$ ls /mnt/rpool
@  @home  snapshots  @var_log
$ ls /mnt/rpool/snapshots
home  root

Where snapshots, snapshots/home, and snapshots/root are directories (as opposed to subvolumes).

kimono-koans commented 2 years ago

Where snapshots, snapshots/home, and snapshots/root are directories (as opposed to subvolumes).

Might be best to download the latest bits and try again first.

Next, if this doesn't work, I think this still comes down to parsing. btrfs sub list -s / gives one a path and this path is joined with mount point given by /proc/mounts. Is there something about your config that would make this joined path not the same as actual path to the snapshot?

KodyVB commented 2 years ago

I just downloaded the new version with cargo install --git "https://github.com/kimono-koans/httm.git", then ran doas httm ~/ with no success. Then I did: doas btrfs subvolume create /home/test and doas btrfs subvolume snapshot -r /home /home/test/test, and when I ran doas httm ~/, I could not see the snapshot.

Running doas btrfs subvolume list -s / gets me:

ID 3005 gen 599385 cgen 198847 top level 5 otime 2021-10-31 12:19:14 path @
ID 7309 gen 591271 cgen 466749 top level 5 otime 2022-04-03 05:50:56 path snapshots/home/@home.20220403T0550
ID 8040 gen 591271 cgen 521624 top level 5 otime 2022-05-01 00:00:01 path snapshots/home/@home.20220501T0000
ID 8041 gen 591271 cgen 521690 top level 5 otime 2022-05-01 00:32:41 path snapshots/root/@.20220501T0032
ID 8208 gen 598434 cgen 535944 top level 259 otime 2022-05-08 19:54:17 path @home/kody/.local/share/Steam
ID 8360 gen 591271 cgen 547847 top level 5 otime 2022-05-15 00:00:01 path snapshots/home/@home.20220515T0000
ID 8370 gen 591271 cgen 548672 top level 5 otime 2022-05-15 13:48:46 path snapshots/root/@.20220515T1348
ID 8550 gen 591271 cgen 561834 top level 5 otime 2022-05-22 05:50:46 path snapshots/home/@home.20220522T0550
ID 8555 gen 591271 cgen 562097 top level 5 otime 2022-05-22 09:17:13 path snapshots/root/@.20220522T0917
ID 8753 gen 591271 cgen 574780 top level 5 otime 2022-05-29 05:50:51 path snapshots/home/@home.20220529T0550
ID 8771 gen 591271 cgen 576575 top level 5 otime 2022-05-29 22:18:24 path snapshots/root/@.20220529T2218
ID 8879 gen 591271 cgen 582559 top level 5 otime 2022-06-02 10:31:18 path snapshots/root/@.20220602T1031
ID 8901 gen 591271 cgen 583936 top level 5 otime 2022-06-03 05:50:33 path snapshots/home/@home.20220603T0550
ID 8919 gen 591271 cgen 585731 top level 5 otime 2022-06-03 22:20:48 path snapshots/root/@.20220603T2220
ID 8925 gen 591271 cgen 585788 top level 5 otime 2022-06-04 05:50:29 path snapshots/home/@home.20220604T0550
ID 8944 gen 591271 cgen 587473 top level 5 otime 2022-06-04 21:03:37 path snapshots/root/@.20220604T2103
ID 8954 gen 591271 cgen 587594 top level 5 otime 2022-06-05 05:50:44 path snapshots/home/@home.20220605T0550
ID 8972 gen 591271 cgen 589369 top level 5 otime 2022-06-05 22:13:38 path snapshots/root/@.20220605T2213
ID 8974 gen 594527 cgen 589385 top level 5 otime 2022-06-06 05:50:44 path snapshots/home/@home.20220606T0550
ID 8992 gen 591271 cgen 591220 top level 5 otime 2022-06-06 22:29:01 path snapshots/root/@.20220606T2229
ID 8996 gen 591276 cgen 591276 top level 5 otime 2022-06-07 05:48:15 path snapshots/home/@home.20220607T0548
ID 9013 gen 592976 cgen 592976 top level 5 otime 2022-06-07 21:39:29 path snapshots/root/@.20220607T2139
ID 9019 gen 593018 cgen 593018 top level 5 otime 2022-06-08 05:50:42 path snapshots/home/@home.20220608T0550
ID 9042 gen 594942 cgen 594942 top level 5 otime 2022-06-08 22:52:51 path snapshots/root/@.20220608T2252
ID 9043 gen 594954 cgen 594953 top level 5 otime 2022-06-08 22:53:08 path snapshots/root/@.20220608T2253
ID 9044 gen 594956 cgen 594955 top level 5 otime 2022-06-08 22:53:40 path snapshots/root/@.20220608T2253_1
ID 9045 gen 594957 cgen 594956 top level 5 otime 2022-06-08 22:53:41 path snapshots/root/@.20220608T2253_2
ID 9046 gen 594962 cgen 594962 top level 5 otime 2022-06-09 05:50:58 path snapshots/home/@home.20220609T0550
ID 9050 gen 595074 cgen 595074 top level 5 otime 2022-06-09 08:12:58 path snapshots/root/@.20220609T0812
ID 9051 gen 595078 cgen 595077 top level 5 otime 2022-06-09 08:13:02 path snapshots/root/@.20220609T0813
ID 9052 gen 595079 cgen 595078 top level 5 otime 2022-06-09 08:13:19 path snapshots/root/@.20220609T0813_1
ID 9053 gen 595080 cgen 595079 top level 5 otime 2022-06-09 08:13:20 path snapshots/root/@.20220609T0813_2
ID 9083 gen 596785 cgen 596784 top level 5 otime 2022-06-09 22:38:10 path snapshots/root/@.20220609T2238
ID 9084 gen 596786 cgen 596785 top level 5 otime 2022-06-09 22:38:19 path snapshots/root/@.20220609T2238_1
ID 9085 gen 596791 cgen 596791 top level 5 otime 2022-06-10 05:50:44 path snapshots/home/@home.20220610T0550
ID 9091 gen 597305 cgen 597305 top level 5 otime 2022-06-10 11:00:01 path snapshots/home/@home.20220610T1100
ID 9092 gen 597421 cgen 597421 top level 5 otime 2022-06-10 12:00:01 path snapshots/home/@home.20220610T1200
ID 9093 gen 597491 cgen 597491 top level 5 otime 2022-06-10 12:35:30 path snapshots/root/@.20220610T1235
ID 9094 gen 597496 cgen 597496 top level 5 otime 2022-06-10 12:35:31 path snapshots/root/@.20220610T1235_1
ID 9095 gen 597513 cgen 597513 top level 5 otime 2022-06-10 12:44:11 path snapshots/root/@.20220610T1244
ID 9096 gen 597514 cgen 597514 top level 5 otime 2022-06-10 12:44:12 path snapshots/root/@.20220610T1244_1
ID 9097 gen 597524 cgen 597524 top level 5 otime 2022-06-10 12:48:56 path snapshots/root/@.20220610T1248
ID 9098 gen 597526 cgen 597525 top level 5 otime 2022-06-10 12:48:57 path snapshots/root/@.20220610T1248_1
ID 9099 gen 597547 cgen 597547 top level 5 otime 2022-06-10 13:00:01 path snapshots/home/@home.20220610T1300
ID 9100 gen 597578 cgen 597577 top level 5 otime 2022-06-10 13:14:38 path snapshots/root/@.20220610T1314
ID 9101 gen 597579 cgen 597578 top level 5 otime 2022-06-10 13:14:39 path snapshots/root/@.20220610T1314_1
ID 9102 gen 597653 cgen 597652 top level 5 otime 2022-06-10 13:52:47 path snapshots/root/@.20220610T1352
ID 9103 gen 597654 cgen 597653 top level 5 otime 2022-06-10 13:52:48 path snapshots/root/@.20220610T1352_1
ID 9104 gen 597668 cgen 597667 top level 5 otime 2022-06-10 14:00:01 path snapshots/home/@home.20220610T1400
ID 9105 gen 597785 cgen 597784 top level 5 otime 2022-06-10 15:00:01 path snapshots/home/@home.20220610T1500
ID 9106 gen 597848 cgen 597847 top level 5 otime 2022-06-10 15:31:19 path snapshots/root/@.20220610T1531
ID 9107 gen 597849 cgen 597848 top level 5 otime 2022-06-10 15:31:20 path snapshots/root/@.20220610T1531_1
ID 9108 gen 597905 cgen 597904 top level 5 otime 2022-06-10 16:00:01 path snapshots/home/@home.20220610T1600
ID 9109 gen 598023 cgen 598022 top level 5 otime 2022-06-10 17:00:01 path snapshots/home/@home.20220610T1700
ID 9110 gen 598141 cgen 598140 top level 5 otime 2022-06-10 18:00:01 path snapshots/home/@home.20220610T1800
ID 9111 gen 598260 cgen 598259 top level 5 otime 2022-06-10 19:00:01 path snapshots/home/@home.20220610T1900
ID 9112 gen 598379 cgen 598378 top level 5 otime 2022-06-10 20:00:01 path snapshots/home/@home.20220610T2000
ID 9113 gen 598504 cgen 598504 top level 5 otime 2022-06-10 21:00:01 path snapshots/home/@home.20220610T2100
ID 9114 gen 598621 cgen 598621 top level 5 otime 2022-06-10 22:00:01 path snapshots/home/@home.20220610T2200
ID 9115 gen 598739 cgen 598738 top level 5 otime 2022-06-10 23:00:01 path snapshots/home/@home.20220610T2300
ID 9116 gen 598745 cgen 598745 top level 5 otime 2022-06-10 23:02:21 path snapshots/root/@.20220610T2302
ID 9117 gen 598752 cgen 598751 top level 5 otime 2022-06-10 23:02:37 path snapshots/root/@.20220610T2302_1
ID 9118 gen 598753 cgen 598752 top level 5 otime 2022-06-10 23:03:05 path snapshots/root/@.20220610T2303
ID 9119 gen 598754 cgen 598753 top level 5 otime 2022-06-10 23:03:06 path snapshots/root/@.20220610T2303_1
ID 9120 gen 598841 cgen 598841 top level 5 otime 2022-06-11 05:50:47 path snapshots/home/@home.20220611T0550
ID 9121 gen 598848 cgen 598848 top level 5 otime 2022-06-11 06:00:01 path snapshots/home/@home.20220611T0600
ID 9122 gen 598892 cgen 598892 top level 5 otime 2022-06-11 07:00:01 path snapshots/home/@home.20220611T0700
ID 9123 gen 598990 cgen 598990 top level 5 otime 2022-06-11 08:00:01 path snapshots/home/@home.20220611T0800
ID 9124 gen 599108 cgen 599108 top level 5 otime 2022-06-11 09:00:01 path snapshots/home/@home.20220611T0900
ID 9125 gen 599226 cgen 599226 top level 5 otime 2022-06-11 10:00:01 path snapshots/home/@home.20220611T1000
ID 9126 gen 599344 cgen 599344 top level 5 otime 2022-06-11 11:00:01 path snapshots/home/@home.20220611T1100
ID 9130 gen 599421 cgen 599421 top level 9129 otime 2022-06-11 11:37:41 path @home/test/test

While running cat /proc/mounts gets me:

proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
sys /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
dev /dev devtmpfs rw,nosuid,relatime,size=8158860k,nr_inodes=2039715,mode=755,inode64 0 0
run /run tmpfs rw,nosuid,nodev,relatime,mode=755,inode64 0 0
efivarfs /sys/firmware/efi/efivars efivarfs rw,nosuid,nodev,noexec,relatime 0 0
/dev/sda2 / btrfs rw,noatime,compress=zstd:3,ssd,discard=async,space_cache,subvolid=3005,subvol=/@ 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev,inode64 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
bpf /sys/fs/bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=30,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=1439 0 0
debugfs /sys/kernel/debug debugfs rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /tmp tmpfs rw,nosuid,nodev,nr_inodes=1048576,inode64 0 0
tracefs /sys/kernel/tracing tracefs rw,nosuid,nodev,noexec,relatime 0 0
mqueue /dev/mqueue mqueue rw,nosuid,nodev,noexec,relatime 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,relatime,pagesize=2M 0 0
fusectl /sys/fs/fuse/connections fusectl rw,nosuid,nodev,noexec,relatime 0 0
configfs /sys/kernel/config configfs rw,nosuid,nodev,noexec,relatime 0 0
ramfs /run/credentials/systemd-sysusers.service ramfs ro,nosuid,nodev,noexec,relatime,mode=700 0 0
/dev/sda2 /mnt/rpool btrfs rw,noatime,compress=zstd:3,ssd,discard=async,space_cache,subvolid=5,subvol=/ 0 0
/dev/sda2 /home btrfs rw,noatime,compress=zstd:3,ssd,discard=async,space_cache,subvolid=259,subvol=/@home 0 0
/dev/sda2 /var/log btrfs rw,noatime,compress=zstd:3,ssd,discard=async,space_cache,subvolid=260,subvol=/@var_log 0 0
/dev/sda1 /boot/EFI vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=1633872k,nr_inodes=408468,mode=700,uid=1000,gid=984,inode64 0 0
//192.168.1.64/KodyMedia /mnt/media cifs rw,nosuid,nodev,relatime,vers=3.1.1,cache=strict,username=kody,uid=1000,noforceuid,gid=984,noforcegid,addr=192.168.1.64,file_mode=0755,dir_mode=0755,soft,nounix,mapposix,rsize=4194304,wsize=4194304,bsize=1048576,echo_interval=60,actimeo=1 0 0
zell-mbc commented 2 years ago

I see the same issue with the latest release I pulled just now, httm-bin 0.11.5-1 Very similar setup to the thread opener by the look of it. When I launch sudo httm -i -R ~/ I only see the current files, not the versions residing in my snapshots.

I have my drive root mounted to /mnt/ and all snapshots reside under /mnt/snapshots Let me know if there is any other detail I can provide.

kimono-koans commented 2 years ago

@KodyVB and @zell-mbc, you might try the latest bits when you have the time. Thanks!

zell-mbc commented 2 years ago

Will do as soon as it becomes avaiable, but that last tag here is is still 0.11.5-1, which is what I got? Same as here: https://aur.archlinux.org/packages?O=0&SeB=nd&K=httm&outdated=&SB=p&SO=d&PP=50&submit=Go)

KodyVB commented 2 years ago

I just upgraded to v0.11.6 and it's now working as expected for me.

kimono-koans commented 2 years ago

That's what we like to hear! I'm closing now. @zell-mbc if you continue to have issues I'll ask you open a new issue. Thanks both of you.

zell-mbc commented 2 years ago

I just upgraded to v0.11.6 and it's now working as expected for me.

Same here! Thanks for providing this tool!