Skip to content

i13e/timeshift-autosnap-wrapper

Repository files navigation

timeshift-autosnap-wrapper

This script serves as a wrapper for timeshift-autosnap, designed to run before package upgrades using a Pacman hook. Its primary purpose is to prevent the creation of multiple snapshots when combining timeshift-autosnap with AUR helpers. To execute a system update with this wrapper, simply run autosnap-wrapper.

Supported AUR Helpers

  • Paru
  • Yay

Features

  • Creates Timeshift snapshots with unique comments.
  • Deletes old snapshots generated by this script.
  • Automatically generates Grub entries if the grub-btrfs package is installed.
  • Can be manually triggered by running the timeshift-autosnap command with elevated privileges.
  • Allows temporarily skipping the autosnapshot by setting the SKIP_AUTOSNAP environment variable (e.g., sudo SKIP_AUTOSNAP= pacman -Syu).
  • Ensures only one snapshot is taken when using AUR helpers yay and paru.

/etc/timeshift-autosnap.conf Options

  • skipAutosnap - If set to true, the script won't be executed.
  • deleteSnapshots - If set to false, old snapshots won't be deleted.
  • maxSnapshots - Specifies the maximum number of old snapshots to keep.
  • updateGrub - If set to false, Grub entries won't be generated.
  • snapshotDescription - Specifies the value used to differentiate snapshots created using timeshift-autosnap.

What Was Patched

AUR helpers invoke Pacman multiple times during any system update, and the timeshift-autosnap hook runs each time Pacman updates packages. This often results in the creation of multiple partial-update snapshots during an upgrade, making timeshift-autosnap's function less useful and cluttering the system.

Our Solution

To address this issue, we've implemented a way to signal to the various spawned Pacman processes whether a snapshot has been taken during an update. Initially, we set up a location for a lockfile, the presence of which indicates that a snapshot has been created. We save this information in an environment variable and pass it to each instance of Pacman spawned by our AUR helper.

On the first run, the autosnap hook detects that our environment variable is declared, but the file does not yet exist. In this case, we touch the file as the user who called Pacman via sudo and then proceed with the update. On subsequent runs, the lockfile exists, so we set the SKIP_AUTOSNAP variable before running timeshift-autosnap, preventing the creation of additional snapshots. After our AUR helper completes its tasks, our wrapper script removes the lockfile as a final cleanup step.

It's important to note that all these actions occur only when our AUR helper is launched through autosnap-wrapper and when __AUTOSNAP_LOCK is defined. Otherwise, timeshift-autosnap is invoked normally without modification.

Notes

  • This script works in both BTRFS and RSYNC modes.
  • While it was designed with Arch and Arch-based distributions in mind, it can be easily adapted for other Linux distributions.
  • You can manually specify the AUR helper you are using by adding the following line to your ~/.profile: export AUR_HELPER=EXAMPLE, replacing EXAMPLE with your chosen AUR helper name in lowercase.

Contribution

We welcome all new ideas and contributions! If you have suggestions to make this patch easier to use or want to implement support for additional AUR helpers, please feel free to get involved. Your contributions are greatly appreciated.