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.35k stars 29 forks source link

Doesn't detect btrfs snapshots #102

Closed dionorgua closed 6 months ago

dionorgua commented 7 months ago

Describe the bug httm doesn't detect snapshots for me (just local access)

There is no "single" way to manage snapshots. So I think my layout is somehow special.

I'm using "flat" layout (where root subvol with subvolid=5 is not mounted). I've just a few 'subvolumes' in subvolid=5 with names like rootfs, home, etc.

To start using snapshots I've created additional snapshots subvolume and mounted it to /.snapshots.

% ls -1 /.snapshots 
containers.20240307T1351
containers.20240307T1400
home.20240307T1351
home.20240307T1400
rootfs.20240307T1351
rootfs.20240307T1400
work.20240307T1351
work.20240307T1400

Just migrated from snapper because of I don't like it's .snapshots layout inside volume

Snapshots are managed by btrbk.

 sudo btrfs subvolume list -a -s ~       
ID 262 gen 663 cgen 662 top level 261 otime 2024-03-07 13:51:03 path <FS_TREE>/snapshots/rootfs.20240307T1351
ID 263 gen 664 cgen 663 top level 261 otime 2024-03-07 13:51:03 path <FS_TREE>/snapshots/home.20240307T1351
ID 264 gen 664 cgen 664 top level 261 otime 2024-03-07 13:51:03 path <FS_TREE>/snapshots/work.20240307T1351
ID 265 gen 665 cgen 665 top level 261 otime 2024-03-07 13:51:03 path <FS_TREE>/snapshots/containers.20240307T1351
ID 266 gen 684 cgen 683 top level 261 otime 2024-03-07 14:00:09 path <FS_TREE>/snapshots/rootfs.20240307T1400
ID 267 gen 685 cgen 684 top level 261 otime 2024-03-07 14:00:09 path <FS_TREE>/snapshots/home.20240307T1400
ID 268 gen 685 cgen 685 top level 261 otime 2024-03-07 14:00:09 path <FS_TREE>/snapshots/work.20240307T1400
ID 269 gen 686 cgen 686 top level 261 otime 2024-03-07 14:00:09 path <FS_TREE>/snapshots/containers.20240307T1400

I think that FS_TREE may confuse httm. Plus it's not enough to just strip it because 'FS_TREE/snapshots/' here means snapshots subvolume, not mount point.

I think follwed line from mount describes it:

/dev/mapper/elitepad4-rootfs on /.snapshots type btrfs (rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=261,subvol=/snapshots)

I think it's similar to https://github.com/kimono-koans/httm/issues/85

To Reproduce Steps to reproduce the behavior:

  1. httm --unique=all --debug ~/.zshrc

Expected behavior Ideally it should automatically guess where snapshots are. Maybe provide some CLI parameter or env variable if autodetect is too diffficult.

Additional context Add any other context about the problem here. Perhaps you should include system details like:

kimono-koans commented 7 months ago

Thank you for the detailed bug report.

The dataset/subvol is called /snapshots but is mounted at /.snapshots?

I think what happened here is somewhere along the way I assumed the btrfs command output (only way to easily obtain snapshot info) corresponds to a directory and not a dataset. I'm not a btrfs user, but I'll whip up a test case soon.

kimono-koans commented 7 months ago

Are you running httm using sudo or equivalent? btrfs snapshots are by default privileged.

dionorgua commented 7 months ago

Yes. They are similar for my setup, but they can be absolutely different.

I think right now 'flat' layout is most common. It means that 'top level' subvolume (with id=5) is used to store other subvolumes. Usually this 'top level' subvolume is not mounted. But can be mounted if needed (for example to add more subvolumes):

sudo mount -o subvolid=5 /dev/mapper/elitepad4-rootfs /mnt/tmp
% ls -1 /mnt/tmp
bbcrypt
containers
home
root
snapshots
work

Please note that not every 'directory' here is subvolume. For example to make /var/cache a subvolume I can do one of:

In both cases later I'll need to add fstab entry to mount that subvolume as /var/cache. Or just mount it with -o subvol=/var_cache or -o subvol=/var/cache depending on which kind of 'flat' layout I use :)

There is also 'nested' layout where that default subvolid=5 is used as root filesystem. And every subvolume is created as is (without need to mount subvolume).

Right now 'flat' layout is usually used for 'system directories' and sometimes 'nested' is used for subvolumes inside /home/USER.

But whole situation is even more complex. Nothing prevents using some sort of 'mixed' setup where, for example, /var is 'flat' subvolume and /var/cache is nested inside /var

I'm not sure that it's possible to handle all possible cases automatically. And I'm not sure that you want to implement all of this.

I just tried httm first time, so I don't know all it's features. But to find all possible subvolumes for ~/.zshrc you need to:

% sudo btrfs subvolume show /home
home
        Name:                   home
        UUID:                   d6106243-9294-cd45-a62c-449ae19f27ab
        Parent UUID:            -
        Received UUID:          -
        Creation time:          2024-03-06 16:33:47 +0100
        Subvolume ID:           257
        Generation:             1311
        Gen at creation:        8
        Parent ID:              5
        Top level ID:           5
        Flags:                  -
        Send transid:           0
        Send time:              2024-03-06 16:33:47 +0100
        Receive transid:        0
        Receive time:           -
        Snapshot(s):
                                snapshots/home.20240307T1351
                                snapshots/home.20240307T1400
                                snapshots/home.20240307T1644
                                snapshots/home.20240307T1700
                                snapshots/home.20240307T1800
                                snapshots/home.20240307T1900
        Quota group:            n/a

You'll also get list of snapshots here

I know that this is too complex.. Plus I don't know about performance.

dionorgua commented 7 months ago

Are you running httm using sudo or equivalent? btrfs snapshots are by default privileged.

Tried both. But I can access /.snapshots/home.20240307T1800/dion/.zshrc as regular user

kimono-koans commented 7 months ago

I'm not sure that it's possible to handle all possible cases automatically. And I'm not sure that you want to implement all of this.

Yeah, I understand it's pure insanity. btrfs support has been a real pain in my backside.

Would you try cloning and trying this branch? Instructions on how to build are in the README.

dionorgua commented 7 months ago

Hi, It still doesn't work. debug2.txt

kimono-koans commented 7 months ago

I'm not sure that it's possible to handle all possible cases automatically. And I'm not sure that you want to implement all of this.

Yeah, I understand it's pure insanity. btrfs support has been a real pain in my backside.

Would you try cloning and trying this branch? Instructions on how to build are in the README.

Would you take another look? Now works with subvols on different mounts and nested subvols for me. Thanks!

dionorgua commented 7 months ago

I've checked 1f0db4c4214a55c43d4a055453040c13081a8a25. It still doesn't work. debug output changed. It detects snapshots but for some reason it thinks that all snapshots are for / volume

debug3.txt

kimono-koans commented 7 months ago

What is your output re: sudo btrfs subvolume show / and sudo btrfs subvolume show /home, etc.?

dionorgua commented 7 months ago
sudo btrfs subvolume show /
root
        Name:                   root
        UUID:                   95822128-2007-9e4d-b4ad-6aa413bf1717
        Parent UUID:            -
        Received UUID:          -
        Creation time:          2024-03-06 16:33:44 +0100
        Subvolume ID:           256
        Generation:             2621
        Gen at creation:        8
        Parent ID:              5
        Top level ID:           5
        Flags:                  -
        Send transid:           0
        Send time:              2024-03-06 16:33:44 +0100
        Receive transid:        0
        Receive time:           -
        Snapshot(s):
                                snapshots/rootfs.20240307T1351
                                snapshots/rootfs.20240307T1400
                                snapshots/rootfs.20240307T1644
                                snapshots/rootfs.20240307T1700
                                snapshots/rootfs.20240307T1800
                                snapshots/rootfs.20240307T1900
                                snapshots/rootfs.20240307T2000
                                snapshots/rootfs.20240307T2100
                                snapshots/rootfs.20240307T2227
                                snapshots/rootfs.20240307T2353
                                snapshots/rootfs.20240308T0000
                                snapshots/rootfs.20240308T1447
                                snapshots/rootfs.20240308T1500
                                snapshots/rootfs.20240308T1600
                                snapshots/rootfs.20240308T1700
                                snapshots/rootfs.20240308T1800
                                snapshots/rootfs.20240308T1900
                                snapshots/rootfs.20240308T2000
                                snapshots/rootfs.20240308T2100
        Quota group:            n/a
% sudo btrfs subvolume show /home
home
        Name:                   home
        UUID:                   d6106243-9294-cd45-a62c-449ae19f27ab
        Parent UUID:            -
        Received UUID:          -
        Creation time:          2024-03-06 16:33:47 +0100
        Subvolume ID:           257
        Generation:             2622
        Gen at creation:        8
        Parent ID:              5
        Top level ID:           5
        Flags:                  -
        Send transid:           0
        Send time:              2024-03-06 16:33:47 +0100
        Receive transid:        0
        Receive time:           -
        Snapshot(s):
                                snapshots/home.20240307T1351
                                snapshots/home.20240307T1400
                                snapshots/home.20240307T1644
                                snapshots/home.20240307T1700
                                snapshots/home.20240307T1800
                                snapshots/home.20240307T1900
                                snapshots/home.20240307T2000
                                snapshots/home.20240307T2100
                                snapshots/home.20240307T2227
                                snapshots/home.20240307T2353
                                snapshots/home.20240308T0000
                                snapshots/home.20240308T1447
                                snapshots/home.20240308T1500
                                snapshots/home.20240308T1600
                                snapshots/home.20240308T1700
                                snapshots/home.20240308T1800
                                snapshots/home.20240308T1900
                                snapshots/home.20240308T2000
                                snapshots/home.20240308T2100
        Quota group:            n/a
kimono-koans commented 7 months ago

I'm not sure that it's possible to handle all possible cases automatically. And I'm not sure that you want to implement all of this.

Yeah, I understand it's pure insanity. btrfs support has been a real pain in my backside. Would you try cloning and trying this branch? Instructions on how to build are in the README.

Would you take another look at https://github.com/kimono-koans/httm/tree/fix_btrfs?

dionorgua commented 7 months ago

77c878c547028a278dee8f810f96f746ca519f9b

Still same. debug4.txt

kimono-koans commented 7 months ago

77c878c

Still same. debug4.txt

I think this was my fault. I think httm saw that your snapshot dir looked like a Snapper snapshot directory and just ran from there. It should work now?

Re: mine, I have one root and two subs, all contain snaps from different filesystems and all are detected.

dionorgua commented 7 months ago

8d9b3d8d19279176504ea340a7c8058792073aa7 doesn't work. debug5.txt

kimono-koans commented 7 months ago

Can you give me your mount | grep btrfs?

dionorgua commented 7 months ago
% mount | grep btrfs
/dev/mapper/elitepad4-rootfs on / type btrfs (rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=256,subvol=/root)
/dev/mapper/elitepad4-rootfs on /.snapshots type btrfs (rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=261,subvol=/snapshots)
/dev/mapper/elitepad4-rootfs on /home type btrfs (rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=257,subvol=/home)
/dev/mapper/elitepad4-rootfs on /home/bbcrypt type btrfs (rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=260,subvol=/bbcrypt)
/dev/mapper/elitepad4-rootfs on /home/dion/.local/share/containers type btrfs (rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=259,subvol=/containers)
/dev/mapper/elitepad4-rootfs on /home/work type btrfs (rw,noatime,compress=zstd:3,ssd,discard=async,space_cache=v2,subvolid=258,subvol=/work)
/dev/mapper/elitepad4_cryptboot on /boot type btrfs (rw,noatime,ssd,discard=async,space_cache=v2,subvolid=5,subvol=/)
kimono-koans commented 7 months ago

I fixed a small issue which may impact your use case given the actual semantics of a Rust std library function, but now it should work?

Would you take another look at https://github.com/kimono-koans/httm/tree/fix_btrfs?

I'll let you see my test setup, can you identify a difference? Your subvolumes don't lead with @. Anything else? --

% mount | grep btrfs
/dev/zd0 on /mnt type btrfs (rw,relatime,ssd,space_cache=v2,subvolid=5,subvol=/)
/dev/zd0 on /mnt/garden type btrfs (rw,relatime,ssd,space_cache=v2,subvolid=256,subvol=/@garden)
/dev/zd0 on /mnt/veranda type btrfs (rw,relatime,ssd,space_cache=v2,subvolid=265,subvol=/@veranda)
% sudo btrfs sub show /mnt
/
    Name:           <FS_TREE>
    UUID:           dcba9a17-16d3-495a-9899-334ecca50f2b
    Parent UUID:        -
    Received UUID:      -
    Creation time:      2024-03-07 16:36:31 -0600
    Subvolume ID:       5
    Generation:         41
    Gen at creation:    0
    Parent ID:      0
    Top level ID:       0
    Flags:          -
    Send transid:       0
    Send time:      2024-03-07 16:36:31 -0600
    Receive transid:    0
    Receive time:       -
    Snapshot(s):
                @garden/root-v1
                @garden/root-v2
                @garden/root-v3
                @garden/root-v4
                @garden/root-v5
                1
                2
                root-v5
                root-v6
% sudo btrfs sub show /mnt/garden
@garden
    Name:           @garden
    UUID:           4e9bf1a7-8f68-3444-babf-3867986776a5
    Parent UUID:        -
    Received UUID:      -
    Creation time:      2024-03-07 16:37:10 -0600
    Subvolume ID:       256
    Generation:         44
    Gen at creation:    7
    Parent ID:      5
    Top level ID:       5
    Flags:          -
    Send transid:       0
    Send time:      2024-03-07 16:37:10 -0600
    Receive transid:    0
    Receive time:       -
    Snapshot(s):
                @garden/1
                @garden/2
                @garden/3
                @garden/4
                5
sudo btrfs sub show /mnt/veranda
@veranda
    Name:           @veranda
    UUID:           cfecde7f-a5ad-a642-8e85-7eea0aae52ab
    Parent UUID:        -
    Received UUID:      -
    Creation time:      2024-03-08 13:58:07 -0600
    Subvolume ID:       265
    Generation:         43
    Gen at creation:    24
    Parent ID:      5
    Top level ID:       5
    Flags:          -
    Send transid:       0
    Send time:      2024-03-08 13:58:07 -0600
    Receive transid:    0
    Receive time:       -
    Snapshot(s):
                @garden/v1
                @garden/v2
                @garden/v4
                v3
                v5
                v6
kimono-koans commented 7 months ago

Oops there was something wrong re: btrfs root parsing, please make sure to try at least: https://github.com/kimono-koans/httm/commit/b97d8cf43babd0df0362c634e06cd4ff0c87591f.

dionorgua commented 7 months ago

Hi, tried both 737bd0739335f3d9ffe12c9da8900e4cf2208256 and b97d8cf43babd0df0362c634e06cd4ff0c87591f. Both doesn't work.

debug6.txt

I don't see much differences (except I use / on btrfs). Yes, I don't use @ prefix. Btw I also have /boot on btrfs (different block device so different filesystem). If I temporary unmount it httm doesn't work at all. It prints followed:

httm --unique=all --debug ~/.zshrc 
Error: httm could not find any valid datasets on the system

Would it help if I create VM with setup similar to that I use and provide you with ssh to it? If so, can you share your SSH public key?

kimono-koans commented 7 months ago

httm --unique=all --debug ~/.zshrc Error: httm could not find any valid datasets on the system

Are you sure you are using sudo when you exec httm? My guess is you are using sudo when you exec btrfs, but not when you exec httm as discussed above.

I've added some error handling in the latest to inform the user.

Would it help if I create VM with setup similar to that I use and provide you with ssh to it? If so, can you share your SSH public key?

I'd be pleased to, but I really think it's something silly like above.

dionorgua commented 7 months ago

Ahh. Yes.. You're right.. I completely forgot about this. So with sudo it works!.

kimono-koans commented 7 months ago

https://github.com/kimono-koans/httm/pull/103

dionorgua commented 7 months ago

Thanks for help!

dionorgua commented 6 months ago

Hi,

It doesn't work anymore with https://github.com/kimono-koans/httm/releases/tag/0.37.4

log_new.txt

kimono-koans commented 6 months ago

Okay, you're running httm with sudo and there are no other error messages?

Could you please give me your sudo btrfs subvolume show... output for /home and /.snapshots and /?

I think I just added a WARN notice when your snapshots are perhaps unmounted to master. Are your snapshots mounted?

dionorgua commented 6 months ago

Yes. root this time. Whole output was captured including stderr

sudo httm --unique=all --debug ~/.zshrc >/tmp/log_new.txt 2>&1
% sudo btrfs subvolume show /home                                                                            
[sudo] password for dion: 
home
        Name:                   home
        UUID:                   d6106243-9294-cd45-a62c-449ae19f27ab
        Parent UUID:            -
        Received UUID:          -
        Creation time:          2024-03-06 16:33:47 +0100
        Subvolume ID:           257
        Generation:             15535
        Gen at creation:        8
        Parent ID:              5
        Top level ID:           5
        Flags:                  -
        Send transid:           0
        Send time:              2024-03-06 16:33:47 +0100
        Receive transid:        0
        Receive time:           -
        Snapshot(s):
                                snapshots/home.20240314T0027
                                snapshots/home.20240315T1209
                                snapshots/home.20240315T1300
                                snapshots/home.20240315T1400
                                snapshots/home.20240315T1500
                                snapshots/home.20240315T1600
                                snapshots/home.20240315T1700
                                snapshots/home.20240315T1800
                                snapshots/home.20240315T1900
                                snapshots/home.20240315T2000
                                snapshots/home.20240315T2100
                                snapshots/home.20240315T2200
                                snapshots/home.20240315T2300
                                snapshots/home.20240316T0000
                                snapshots/home.20240316T0100
                                snapshots/home.20240316T0200
                                snapshots/home.20240316T0300
                                snapshots/home.20240316T0400
                                snapshots/home.20240316T0500
                                snapshots/home.20240316T0600
                                snapshots/home.20240316T0700
                                snapshots/home.20240316T0800
                                snapshots/home.20240316T0900
                                snapshots/home.20240316T1000
                                snapshots/home.20240316T1100
                                snapshots/home.20240316T1200
                                snapshots/home.20240316T1300
                                snapshots/home.20240316T1400
                                snapshots/home.20240316T1500
                                snapshots/home.20240316T1600
                                snapshots/home.20240316T1700
                                snapshots/home.20240316T2123
                                snapshots/home.20240316T2200
        Quota group:            n/a
% sudo btrfs subvolume show /.snapshots
snapshots
        Name:                   snapshots
        UUID:                   aa7a8441-0210-0c4a-aa8d-2855630c5e74
        Parent UUID:            -
        Received UUID:          -
        Creation time:          2024-03-07 13:35:43 +0100
        Subvolume ID:           261
        Generation:             15490
        Gen at creation:        632
        Parent ID:              5
        Top level ID:           5
        Flags:                  -
        Send transid:           0
        Send time:              2024-03-07 13:35:43 +0100
        Receive transid:        0
        Receive time:           -
        Snapshot(s):
        Quota group:            n/a
% sudo btrfs subvolume show /          
root
        Name:                   root
        UUID:                   95822128-2007-9e4d-b4ad-6aa413bf1717
        Parent UUID:            -
        Received UUID:          -
        Creation time:          2024-03-06 16:33:44 +0100
        Subvolume ID:           256
        Generation:             15537
        Gen at creation:        8
        Parent ID:              5
        Top level ID:           5
        Flags:                  -
        Send transid:           0
        Send time:              2024-03-06 16:33:44 +0100
        Receive transid:        0
        Receive time:           -
        Snapshot(s):
                                snapshots/rootfs.20240314T0027
                                snapshots/rootfs.20240315T1209
                                snapshots/rootfs.20240315T1300
                                snapshots/rootfs.20240315T1400
                                snapshots/rootfs.20240315T1500
                                snapshots/rootfs.20240315T1600
                                snapshots/rootfs.20240315T1700
                                snapshots/rootfs.20240315T1800
                                snapshots/rootfs.20240315T1900
                                snapshots/rootfs.20240315T2000
                                snapshots/rootfs.20240315T2100
                                snapshots/rootfs.20240315T2200
                                snapshots/rootfs.20240315T2300
                                snapshots/rootfs.20240316T0000
                                snapshots/rootfs.20240316T0100
                                snapshots/rootfs.20240316T0200
                                snapshots/rootfs.20240316T0300
                                snapshots/rootfs.20240316T0400
                                snapshots/rootfs.20240316T0500
                                snapshots/rootfs.20240316T0600
                                snapshots/rootfs.20240316T0700
                                snapshots/rootfs.20240316T0800
                                snapshots/rootfs.20240316T0900
                                snapshots/rootfs.20240316T1000
                                snapshots/rootfs.20240316T1100
                                snapshots/rootfs.20240316T1200
                                snapshots/rootfs.20240316T1300
                                snapshots/rootfs.20240316T1400
                                snapshots/rootfs.20240316T1500
                                snapshots/rootfs.20240316T1600
                                snapshots/rootfs.20240316T1700
                                snapshots/rootfs.20240316T2123
                                snapshots/rootfs.20240316T2200
        Quota group:            n/a
kimono-koans commented 6 months ago

I'd ask that you build from master. I'm curious if some warning would be given now.

kimono-koans commented 6 months ago

Please upgrade to latest: https://github.com/kimono-koans/httm/releases/tag/0.37.6

dionorgua commented 6 months ago

Still doesn't work. But now with some logs: log_new.txt

kimono-koans commented 6 months ago

Obviously the subvol name /snapshots is not resolving to the subvol mount /.snapshots, which is weird because it was working for me.

I think perhaps this one is my fault. Perhaps I was using the wrong std library function. Would you build from this branch? See: https://github.com/kimono-koans/httm/tree/fix_btrfs_subvol_names

Thanks!

dionorgua commented 6 months ago

It works! log_new_works.txt