Improving the timeshift ouput when installing a package using APT

I was not a fan of the lack of detail in the “pre-apt” description in the timeshift app. It was hard to remember what was installed or removed.

So I, well me and AI, came up with a hook/script pair to make the timeshift description show the apt command that was used.

My new /etc/apt/apt.conf.d/80timeshift file:

DPkg::Pre-Invoke { "/usr/local/sbin/timeshift-apt-hook || true"; };
DPkg::Post-Invoke { "/etc/grub.d/41_snapshots-btrfs || true"; };

And my hook is in /usr/local/sbin/timehift-apt-hook:

#!/bin/sh
set -e

# Fetch the parent process command line (the actual apt command)
PARENT_PID=$PPID
PARENT_NAME=$(ps -p $PARENT_PID -o comm=)

# If the parent is a shell, grab the grandparent process instead
if [ "$PARENT_NAME" = "sh" ] || [ "$PARENT_NAME" = "bash" ]; then
    GPID=$(ps -p $PARENT_PID -o ppid= | tr -d ' ')
    APT_CMD=$(ps -ho args $GPID | sed 's/"/\"/g')
else
    APT_CMD=$(ps -ho args $PARENT_PID | sed 's/"/\"/g')
fi

[ -z "$APT_CMD" ] && APT_CMD="apt operation"

# Create a single snapshot and pipe stderr/stdout to the system journal
    timeshift --create --comments "apt; $APT_CMD" --scripted 2>&1 \
        | logger -t timeshift-apt-hook || true


I hope the cut and paste came through without any missing information.

1 Like

Thanks for this — really good catch. A list of identical “pre-apt” entries is exactly the wrong thing when you’re trying to pick a rollback point, and putting the actual apt command in the comment fixes it in both the Timeshift list and the grub-btrfs boot menu.

I’ve adopted it into butterknife with a few small hardening tweaks.

I’m not respinning the ISO just for this — it’ll be in the next release along with some other queued changes.

1 Like

I just looked at your upcoming timeshift-apt-hook script and tested it. If it was up to me, I’d change the constant part of the tag to “pre-”. That way it’s obvious that this snapshot is before the apt install

5 > 2026-08-01_11-01-41 O pre- apt install borgbackup

versus

6 > 2026-08-01_11-40-34 O apt; apt install sl

Obviously, I can change it anytime with nano :grinning_face:

This is good stuff. JF. version 0.2.15

I just built a fresh system with butterknife 0.2.15 and it went cleanly. Here’s a screenshot of timeshift output without any deletions:

I think this is the way to go. I think I still need to check the timeshift settings. I just want daily.