I’m a novice user (not a developer) and am looking ahead to the Fedora 41 release coming up. I have been using the btrfs-assistant python3-dnf-plugin-snapper setup to provide a really basic, yet helpful snapshot/rollback feature, which automatically takes pre/post snapshots whenever I use dnf to install/remove or upgrade.
I realize that this would not work ootb with dnf5, so I’ve been lurking and seeing if there will be a solution. Thanks to various users here (and on Reddit) I think the following is a solution.
I just want to make it public, all in one post, so folks can comment on it.
Here’s how to have a simple snapper auto-snapshot setup in Fedora 41 with dnf5:
First install:
sudo dnf install btrfs-assistant python3-dnf-plugin-snapper
Snapper settings in Btrfs Assistant (these meet my needs; your settings may be different):
Create new config “root”, Backup path: /
- Disable timeline snapshots
- Snapper timeline disabled
- Snapper cleanup enabled
- Snapper boot disabled
- Apply systemd changes
- Save
Next is the stuff necessary for Fedora 41/dnf5:
sudo dnf install libdnf5-plugin-actions
then create a new file:
sudo nano /etc/dnf/libdnf5-plugins/actions.d/snapper.actions
Add this to the file (This came from here and Reddit. Not sure which is the chicken or egg)
# 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
Write/Exit file
So far I’ve tested in a VM and it works as expected. I hope this is helpful to see it all in one post.