Dnf5 snapper.actions gives no description of the package installed

I have created the snapper.actions files with the template provided in the documentation:

# Creates pre snapshot before the transaction and stores the snapshot number in the "tmp.snapper_pre_number" variable.
pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_pre_number=$(snapper\ create\ -t\ pre\ -p)"

# If the variable "tmp.snapper_pre_number" exists, it creates post snapshot after the transaction and removes the variable "tmp.snapper_pre_number".
post_transaction::::/usr/bin/sh -c [\ -n\ "\${tmp.snapper_pre_number}"\ ]\ &&\ snapper\ create\ -t\ post\ --pre-number\ "\${tmp.snapper_pre_number}"\ ;\ echo\ tmp.snapper_pre_number

It works correctly except that it does not describe which package is updated and that sort of makes it useless.

Does anybody know how to get the description ?

Added cinnamon, dnf5, f40

I would try adding -d ${pkg.nevra} and see if that does what you want.

As a side note, you should also set the cleanup algorithm to number or those snapshots will never get cleaned up unless you delete them manually.

Out of curiosity, does that run for every package? Will it take multiple snapshots if you install more than one package?

1 Like

Thank you for answering. Adding pkg.nevra did not solve it. Regarding your questions, it only creates one pre and post regardless of the number of packages installed at a time.

Yeah, the problem is on the action syntax itself:

Each non-comment line defines an action and consists of five items separated by colons: callback_name:package_filter:direction:options:command .

If package_filter from that has nothing, you get you value for ${pkg.*} which makes it pretty useless really. It’d be nice to be able to get the dnf command called itself or something in this, because if you set package_filter to * it runs it MULTIPLE times, once per package, and we certainly don’t want multiple snapshots here.

dalto was right though, -d\ '${pkg.nevra}' or even just pkg.name would get you enough to at least provide something, but this actions seems extremely more limited than the python alternative that dnf has already had…

Yep, i gave up and went back to dnf4. That extra speed offered by dnf5 isn’t really that important to me since i only update my system once or twice per month.

i’ve run into the same issue… not even managed to create the action file in the correct directory as it didn’t created snapshots while using dnf5 …

according to dnf5 docs i assumed follwoing directory is correct? isn’t it?

/etc/dnf/libdnf5-plugins/actions.d/

with ah file in it thats acain called for example “snapper.actions” ??

Did you install libdnf5-plugin-actions ?

thx looks like i was missing libdnf5-plugin-actions …

now i’ve got the same issue no thaving ah description or cleanup “tag” …
@fiffian did you ever resolved this issue?

i’ve tested with the ${pkg.xxxx}parameters… none of them work… but ${pid} works for example… so looks like somethings broken with the pkg.xxx arguments

https://dnf5.readthedocs.io/en/stable/libdnf5_plugins/actions.8.html

Nope, i gave up and went back to dnf4.

i’ve found something “working” … but its far from pretty…
my actions file looks like this now:

pre_transaction:*:::/usr/bin/sh -c echo\ "tmp.pkg=‘${pkg.action}’\ ‘${pkg.full_nevra}’"
pre_transaction::::/usr/bin/sh -c echo\ “tmp.snapper_pre_number=$(snapper\ create\ -t\ pre\ -c\ number\ -d\ “${tmp.pkg}”\ -p)”

post_transaction::::/usr/bin/sh -c [\ -n\ “${tmp.snapper_pre_number}”\ ]\ &&\ snapper\ create\ -t\ post\ –pre-number\ “${tmp.snapper_pre_number}”\ -c\ number\ -d\ “${tmp.pkg}”;\ echo\ tmp.snapper_pre_number

so basically i write these pkg.xxx variables in another variable, and this you you could call with the -d parameter inside the snapper commands

output looks like this now, obviously the dnf4 plugin before made much nicer descriptions…

1 Like

modified the action config to include a description

# Get snapshot description
pre_transaction::::/usr/bin/sh -c echo\ "tmp.cmd=$(ps\ -o\ command\ --no-headers\ -p\ '${pid}')"
# Creates pre snapshot before the transaction and stores the snapshot number in the "tmp.snapper_pre_number"  variable.
pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_pre_number=$(snapper\ create\ -t\ pre\ -p\ -d\ '${tmp.cmd}')"

# If the variable "tmp.snapper_pre_number" exists, it creates post snapshot after the transaction and removes the variable "tmp.snapper_pre_number".
post_transaction::::/usr/bin/sh -c [\ -n\ "${tmp.snapper_pre_number}"\ ]\ &&\ snapper\ create\ -t\ post\ --pre-number\ "${tmp.snapper_pre_number}"\ -d\ "${tmp.cmd}"\ ;\ echo\ tmp.snapper_pre_number\ ;\ echo\ tmp.cmd
3 Likes

updated this to include a cleanup algorithm due to a suggestion on the github issue

# /etc/dnf/libdnf5-plugins/actions.d/snapper.actions
# Get snapshot description
pre_transaction::::/usr/bin/sh -c echo\ "tmp.cmd=$(ps\ -o\ command\ --no-headers\ -p\ '${pid}')"
# Creates pre snapshot before the transaction and stores the snapshot number in the "tmp.snapper_pre_number"  variable.
pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_pre_number=$(snapper\ create\ -c\ number\ -t\ pre\ -p\ -d\ '${tmp.cmd}')"

# If the variable "tmp.snapper_pre_number" exists, it creates post snapshot after the transaction and removes the variable "tmp.snapper_pre_number".
post_transaction::::/usr/bin/sh -c [\ -n\ "${tmp.snapper_pre_number}"\ ]\ &&\ snapper\ create\ -c\ number\ -t\ post\ --pre-number\ "${tmp.snapper_pre_number}"\ -d\ "${tmp.cmd}"\ ;\ echo\ tmp.snapper_pre_number\ ;\ echo\ tmp.cmd

1 Like