Package: snapper
Version: 0.10.4-1
Followup-For: Bug #1041748

Dear Maintainer,

I was able to create my own script that does what I am talking about. This
script will use the apt command as the snapshot description.

I will try to submit a pull request into
https://salsa.debian.org/debian/snapper with my enhancements.

`**/etc/apt/apt.conf.d/80snapper**`:

```
DPkg::Pre-Invoke { "/path/to/dpkg-pre-post-snapper.sh pre"; };
DPkg::Pre-Invoke { "/path/to/dpkg-pre-post-snapper.sh post"; };
```

`**/path/to/dpkg-pre-post-snapper.sh**`

```
#!/bin/bash

# we need to work up the process tree to find the apt command that triggered
the call to this script
# get the initial PPID
PARENT_PID=${PPID}
# trim leading spacess
PARENT_PID="${PARENT_PID## }"

# if the command for this PPID is not apt
while [ "$(ps -ho comm "${PARENT_PID}")" != "apt" ] ; do
    # go up one level
    PARENT_PID=$(ps -ho ppid "${PARENT_PID}")
    PARENT_PID="${PARENT_PID## }"                             # trim leading
spacess
done

APT_CMD="$(ps -ho args "${PARENT_PID}")"

SNAPPER_DESCRIPTION="apt; ${APT_CMD}"

# source /etc/default/snapper if it exists
if [ -e /etc/default/snapper ] ; then
    . /etc/default/snapper
fi

# what action are we taking
if [ "$1" = "pre" ] ; then
    # pre, so take a pre snapshot

    # if snapper is installed
    # and if snapper snapshots are not being disabled using the
DISABLE_APT_SNAPSHOT variable
    # and if /etc/snapper/configs/root exists
    if [ -x /usr/bin/snapper ] && [ ! x$DISABLE_APT_SNAPSHOT = 'xyes' ] && [ -e
/etc/snapper/configs/root ] ; then
        # delete any lingering temp files
        rm -f /var/tmp/snapper-apt || true

        # create a snapshot
        # and save the snapshot number for reference later
        snapper create -d "${SNAPPER_DESCRIPTION}" -c number -t pre -p >
/var/tmp/snapper-apt || true

        # clean up snapper
        snapper cleanup number || true
    fi
elif [ "$1" = "post" ] ; then
    # post, so take a post snapshot

    # if snapper is installed
    # and if snapper snapshots are not being disabled using the
DISABLE_APT_SNAPSHOT variable
    # and if the temp file with the snapshot number from the pre snapshot
exists
    if [ -x /usr/bin/snapper ] && [ ! x$DISABLE_APT_SNAPSHOT = 'xyes' ] && [ -e
/var/tmp/snapper-apt ]
    then
        # take a post snapshot and link it to the # of the pre snapshot
        snapper create -d "${SNAPPER_DESCRIPTION}" -c number -t post --pre-
number=`cat /var/tmp/snapper-apt` || true

        # clean up snapper
        snapper cleanup number || true
    fi
fi

```


-- System Information:
Debian Release: 12.0
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.1.0-10-amd64 (SMP w/6 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages snapper depends on:
ii  libboost-thread1.74.0  1.74.0+ds1-21
ii  libc6                  2.36-9
ii  libdbus-1-3            1.14.6-1
ii  libgcc-s1              12.2.0-14
ii  libjson-c5             0.16-2
ii  libmount1              2.38.1-5+b1
ii  libsnapper6            0.10.4-1
ii  libstdc++6             12.2.0-14
ii  libtinfo6              6.4-4

snapper recommends no packages.

snapper suggests no packages.

-- Configuration Files:
/etc/apt/apt.conf.d/80snapper changed [not included]
/etc/default/snapper changed [not included]

-- no debconf information

Reply via email to