Antynea / grub-btrfs

Include btrfs snapshots at boot options. (Grub menu)
GNU General Public License v3.0
745 stars 77 forks source link

How to add multiple target folders to watch for Snapshots #262

Closed FGD-Garuda closed 1 year ago

FGD-Garuda commented 1 year ago

Hello,

Following #261 I would like to know how to include multiple snapshot folders to watch for a change?

I tried with multiple ExecStart lines in sudo systemctl edit --full grub-btrfsd but I get

╰─λ sudo systemctl restart grub-btrfsd
Failed to restart grub-btrfsd.service: Unit grub-btrfsd.service has a bad unit file setting.
See system logs and 'systemctl status grub-btrfsd.service' for details.

I tried just adding the folders at the end of the line, just like this ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots /.snapshots/ad-hoc, but it's not catching the /ad-hoc sub-folder.

Also tried ExecStart="/usr/bin/grub-btrfsd --syslog /.snapshots" && "/usr/bin/grub-btrfsd --syslog /.snapshots/ad-hoc" but it fails to start.

I read the man but couldn't find anything related to this.

This is probably related to how to add multiple ExecStart in any service file and not specifically to grub-btrfsd. I will search for how to do it on any service, in case it works here.

Thanks!

FGD-Garuda commented 1 year ago

Since the unit is a Type=simple, multiple ExecStart are not possible. Changing that to oneshot and grub-btrfsd freezes on start.

So I ended up creating 4 more units, total of 5 and managing them individually. Not very interesting, is there a cleaner way of doing this?

Schievel1 commented 1 year ago

Hi,

thanks for that issue. I am afraid this is not possible by now. I labelled it as enhancement to maybe add that as in a future version.

Schievel1 commented 1 year ago

If the directory and the subdirectories are watched, this should solve your problem, shouldn't it?

FGD-Garuda commented 1 year ago

If the directory and the subdirectories are watched, this should solve your problem, shouldn't it?

Yes. As long as it's not recursive, otherwise it would probably watch all the dirs within each snapshots, but with the previous grub-btrfs method (the one before the daemon) editing the .PATH and adding the lines for each dirs I wanted to watch was working fine. That was how it was watching the dir and "selected" subdirs.

ATM I have to have to use 5 systemd service files for the daemon to watch.

Schievel1 commented 1 year ago

As long as it's not recursive, otherwise it would probably watch all the dirs within each snapshots

This is what the new option --recursive does. Depending on your setup this could be problematic, I see. Because snapshots are basically folders. Meh, I can see now why this is nonsense, but well, I will leave it in as an option. Just in case anyone wants that.

In any way, I also added the option to watch more than one directory. Just add them to the command like you did above: ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots /.snapshots/ad-hoc

I would appreciate if you tried this out. All this forking, inheriting and waiting caused some severe brain damage for me.

/ the old way with the systemd service is still working btw. At least for snapper. We dropped it because it is not working with timeshift anymore. Systemd is not flexible enough here.

FGD-Garuda commented 1 year ago

As long as it's not recursive, otherwise it would probably watch all the dirs within each snapshots

This is what the new option --recursive does. Depending on your setup this could be problematic, I see. Because snapshots are basically folders. Meh, I can see now why this is nonsense, but well, I will leave it in as an option. Just in case anyone wants that.

Thinking about it, if there are no snapshots within the snapshots contained in those subfolders, it should work, as the subvolume is only present in the 1st level below the parent subfolder:

Example:

If I take a bunch of snapshots inside each of those, that will be where the subvolumes will be detected and I would assume nothing will be detected say in /.snapshots/daily/@/usr/share/plasma/look-and-feel/ as there are no subvolumes in there.

I will test this once I see the updated package coming through pacman. Am on 4.12-2 ATM.

In any way, I also added the option to watch more than one directory. Just add them to the command like you did above: ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots /.snapshots/ad-hoc

I would appreciate if you tried this out.

Oh I will for sure! 😄 👍 This method should also work.

It's very good news as there could be 2 options to scan through subfolders.

I will report back, tnx!

Schievel1 commented 1 year ago

As long as it's not recursive, otherwise it would probably watch all the dirs within each snapshots

This is what the new option --recursive does. Depending on your setup this could be problematic, I see. Because snapshots are basically folders. Meh, I can see now why this is nonsense, but well, I will leave it in as an option. Just in case anyone wants that.

Thinking about it, if there are no snapshots within the snapshots contained in those subfolders, it should work, as the subvolume is only present in the 1st level below the parent subfolder:

You can try, but I think it wont. Use flag --verbose and watch syslog to know whats going on. The daemon works in a way that we utilize inotify. That is a linux kernel function that watches directories or files for changes and notifiies the caller if there is one. Inotifywait (that is a wrapper program around that function) does not know what folder is a snapshot or a normal folder. To it the filesystem looks like it does to you when you open it in a file browser. So when you have a snapshot under .\snapshots\ad-hoc it will also establish watches for all the subfolders and files, the subfolders of the subfolders and their files etc. of that snapshot. Given that a snapshot is your whole filesystem tree of the root partition, I guess one snapshot alone will bring it to its knees.

FGD-Garuda commented 1 year ago

A'right, so v4.13 got updated and I tried this usage (with 4 subfolders instead of 2):

ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots /.snapshots/ad-hoc

Works beautifully! I do not use timeshift/snapper, I manage all snapshots manually.

That is a great solution for me.

Thank you very much!

😃