Getting snapper/btrfs-assistant to work with dnf5

I’ll try to tidy up to make sure I understand and give new users the chance to have everything in one set of steps. To simplify, I’ll show a configuration with only snapper (without btrfs-assistant) and without any changes to the standard configuration with which this package is preconfigured (who wants to change something install btrfs-assistant). I’ll also insert the buckup script for both home and root into the file, since these are the two default subvolumes in classic Fedora installations.
I would be grateful :pray:t2: if you could give me feedback on the correctness of everything.

  1. Let’s install snapper:
    sudo dnf install snapper

  2. Let’s tell snapper which subvolumes to snapshot:
    sudo snapper -c root create-config /
    and
    sudo snapper -c home create-config /home

  3. Let’s install the other necessary packages:
    sudo dnf install python3-dnf-plugin-snapper libdnf5-plugin-actions

  4. Let’s create/edit the file where we want to insert the script:
    sudo nano /etc/dnf/libdnf5-plugins/actions.d/snapper.actions

and insert the following content inside:

# Get the snapshot description
pre_transaction::::/usr/bin/sh -c echo\ "tmp.cmd=$(ps\ -o\ command\ --no-headers\ -p\ '${pid}')"

# Creates pre snapshots for root and home and stores snapshot numbers in variables
pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_pre_root=$(snapper\ -c\ root\ create\ -t\ pre\ -p\ -d\ '${tmp.cmd}')"
pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_pre_home=$(snapper\ -c\ home\ create\ -t\ pre\ -p\ -d\ '${tmp.cmd}')"

# Creates post snapshots for root and home if pre snapshot numbers exist
post_transaction::::/usr/bin/sh -c [\ -n\ "${tmp.snapper_pre_root}"\ ]\ &&\ snapper\ -c\ root\ create\ -t\ post\ --pre-number\ "${tmp.snapper_pre_root}"\ -d\ "${tmp.cmd}"
post_transaction::::/usr/bin/sh -c [\ -n\ "${tmp.snapper_pre_home}"\ ]\ &&\ snapper\ -c\ home\ create\ -t\ post\ --pre-number\ "${tmp.snapper_pre_home}"\ -d\ "${tmp.cmd}"
  1. Save and exit.

I think it should also be specified that this configuration will not work for all updates and installations that occur via GNOME Software because it uses PackageKit (which does not work with snapper); it should also be specified that any use of snapper to boot the system from a specific snapshot (in case the system has problems booting) would require the grub-btrfs package and additional configurations; however, this package is not present in the Fedora repositories at the moment.

I hope everything is correct; I await your feedback.

2 Likes