Venom1991 / refind-btrfs

Generate rEFInd manual boot stanzas from Btrfs snapshots
GNU General Public License v3.0
144 stars 8 forks source link

Is it possible to change the converted rw snapshots naming? #18

Closed rizzini closed 2 years ago

rizzini commented 2 years ago

The actual naming is pretty awesome already, but I would like, if possible, to choose my own.

I tried to search for *rwsnap* inside your source code, which I'm not familiar with, but I can find punctual patterns in code and edit them, but I couldn't.

Great job with this tool. It just works, which is what Linux is all about.

Venom1991 commented 2 years ago

The naming mechanism is sort of "dynamic" and it's implemented here and here.

So, I believe that introducing a configurable format string option would provide enough customizability.
This string could then be comprised of certain predefined variables such as "source_stanza_name", "date_of_creation" (full date with time), "time_of_creation" (time only), "destination_snapshot_description" (currently, it's always determined to be "rwsnap") and "source_snapshot_id" (original snapshot's ID). I can't really think of any additional variables. The "source_snapshot_id" variable would have to exist somewhere in this format string because of the uniqueness requirement.

With this approach, the default format string would look like this: "{{source_stanza_name}} ({{destination_snapshot_description}}_{{date_of_creation}}_{{source_snapshot_id}})"

The most basic format string could then be defined as: "{{source_snapshot_id}}"

That would look kinda silly but it should be allowed. The variables themselves would have to be enclosed within double curly braces ("{{" and "}}"). Otherwise, they'd be treated as plain text.

Although this feature would be useful, I'd like to take care of another enhancement before implementing this one.

rizzini commented 2 years ago

I'll take a look into the code to really understand what you said and, maybe, try to change it into my needs. I'll keep this post updated if I can get somewhere. The rw subvbolume naming inside the code seems pretty simple. I may be able to do what I want. Thanks for the thorough answer pointing me out where I should look. I would never find it. hehe

rizzini commented 2 years ago

I changed it to be equal BTRBK naming. Worked perfectly. Thanks

@@ -150,7 +150,7 @@

def as_named(self) -> Subvolume:
type_prefix = "ro" if self.is_read_only else "rw"
-        type_prefix += "snap" if self.is_snapshot() else "subvol"
+        #type_prefix += "snap" if self.is_snapshot() else "subvol"

if self.is_newly_created():
created_from = none_throws(self.created_from)
@@ -160,9 +160,11 @@
time_created = self.time_created
num_id = self.num_id

-        formatted_time_created = time_created.strftime("%Y-%m-%d_%H-%M-%S")
+        #formatted_time_created = time_created.strftime("%Y-%m-%d_%H-%M-%S")
+        formatted_time_created = time_created.strftime("%Y%m%dT%H%M")

-        self._name = f"{type_prefix}_{formatted_time_created}_ID{num_id}"
+        #self._name = f"{type_prefix}_{formatted_time_created}_ID{num_id}"
+        self._name = f"ROOT.{formatted_time_created}"

return self
Venom1991 commented 2 years ago

Well, I hope you won't encounter a situation where two snapshots end up with the same timestamp because there be dragons, as they say. :smile:
I've seen it happen on my machine because I've enabled both boot and regular hourly snapshots in Snapper. It's pretty rare, though.

cosmicdan commented 1 year ago

Hi there,

I saw this issue was closed but I was wondering if you considered your config idea some time since? I had a look at the Python code and I'm honestly not experienced enough to try it out myself :)

Consider the list of my snapshots... image ...it would be amazing if my entries appeared descriptively, say ID###_[type]_[description] - description can be truncated if necessary. E.g.

ID205_post_archlinux-appstream-da[...]
ID203_single_snap-pac
ID201_single_Test1

etc...

...then in future, what would also make this really cool is if we could configure and include/exclude list of specific types (e.g. I personally can only imagine needing the hook-generated 'boot' named snapshots in my rEFInd menu).

If I just knew how to actually get these fields from the snapshot, I could probably figure the rest out on my own.

Thank you for your consideration and continued work :+1:

EDIT: Formatting derps, also future idea

Venom1991 commented 1 year ago

@cosmicdan

The "Number", "Type" and "Description" fields are actually defined and managed by Snapper. Maybe even the "Date/Time" field is Snapper's own, I'm not sure.
Anyhow, these are not Btrfs fields and since this tool tries to be agnostic with regards to various snapshot management tools I simply can't implement this feature just now.
Other tools, like Timeshift and btrbk, most probably define their own fields, as well. All I have at my disposal are the timestamp and ID fields belonging to source snapshots.

While this can be done, I'd have to add support for extracting this kind of snapshot metadata from the three previously mentioned snapshot management tools (and possibly add support for more, if any relevant ones appear in the future) which is a prerequisite for implementing this feature.
I simply don't have the time to work on this rather large and complex undertaking, currently.

cosmicdan commented 1 year ago

No worries, thank you for the feedback and honesty.

After some more research, I've actually realized that all this info can be gathered from the .xml file included in the snapper snapshot - there is a "description" field already in there so I can filter on that. So, that's how I can get the fields.

But now I've taken a different, more simple route. Sorry to say that I've since abandoned your project here and instead started to do my own implementation from scratch in a pure .sh script that just runs on boot - take a snapshot and then update my rEFInd immediately after with that new snapshot entry. I also prefer to just boot the snapshots as-is in ro mode (I have the right btrfs subvolumes to avoid the need for booting snapshots in rw mode).

Regardless, thanks a lot for your work here, much respect 👍