You are not logged in.

#1 2021-02-07 01:43:44

doctorzeus
Member
Registered: 2011-12-24
Posts: 79

Pacman Updated Package Logger Script

Don't know if something like this exists already (a cursory google seemed to indicate not).

I made this simple script for my personal use on my Arch dev server and workstation and its so far proven quite useful so decided to share it:

https://github.com/TechtonicSoftware/PacmanUpdateLogger

Basic operation is it is triggered via a pacman hook every time pacman performs an upgrade: The script checks then checks the pacman update logs for the recently upgraded packages against the file names of packages in the package cache. The list of packages is then logged in a timestamped log file.

This I found useful as I can now easily downgrade if needed in case of a system breaking update by just redirecting the specific log file input, e.g.:

pacman -U - < /var/log/pacman_upgrades/210207_122346.log

Would appreciate any suggestions to improve it! Or even if someone could point me to a similar better application?

Many Thanks

Offline

#2 2021-02-07 02:01:46

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: Pacman Updated Package Logger Script

You could just use a custom pacman.conf (or even generate one on the fly) using the archlinux archive mirror.  That way there'd be no need to generate or keep those log files, and it'd work whether or not you had the old package tarballs in your archive.  For example, you can just replace the date (or adjust the script to take the date from parameters) and this will downgrade to a given date:

#!/bin/sh

date=2021/02/01

sed 's|^Include =.*|Server=https://archive.archlinux.org/repos/'"$date"'/$repo/os/$arch|' \
	/etc/pacman.conf >| /tmp/pacold.conf
sudo pacman -Syyuu --config pacold.conf

Note that this does assume that you use "Include = " lines in your pacman.conf for the mirrorlist, and that there are no other "Include =" lines.  If these are not safe assumptions in your case, then it could be adjusted.

EDIT: I suppose this downgrades to what was on the mirrors on a given date, not what you had installed on a given date, so it's a little different that your approach, but I believe it'd acheive the same end goals.

Last edited by Trilby (2021-02-07 02:03:38)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2021-02-07 03:07:54

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 649

Re: Pacman Updated Package Logger Script

You asked for alternative approaches so here is mine. Useful to quickly see when you updated and what changed each time.

Last edited by bulletmark (2021-02-07 03:08:54)

Offline

#4 2021-02-07 05:43:38

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Pacman Updated Package Logger Script

paclog --before 2021-02-03 | paclog --pkglist --logfile /dev/stdin

Gets you the name and version of every installed package at the given date. You can diff that with currently installed versions and/or match it up to versions in the cache.

...

This hook is matching Path and just greps the logfile. Why not match Package instead, and use NeedsTargets? Then pipe this output to pacman -Q - to get the versions of each of those packages and maybe translate them into filenames? Each output would then describe the state after the transaction, not before it, but then you could simply use the most recent log *before* the date you're trying to revert.

How do these downgrade logs handle trying to downgrade to something other than the latest upgrade? If you upgrade foo on Sunday and bar on Monday, and then on Tuesday you want to revert the "foo" update, you need to revert the "bar" update too. And sometimes foo and bar will be multiple updates to the *same* package.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#5 2021-02-11 06:25:15

doctorzeus
Member
Registered: 2011-12-24
Posts: 79

Re: Pacman Updated Package Logger Script

bulletmark wrote:

You asked for alternative approaches so here is mine. Useful to quickly see when you updated and what changed each time.

Looks really good, like how it works for multiple distros!

Does it have a way of directly generating the package file names in the cache without piping the contents of the log file?

Offline

#6 2021-02-11 06:33:16

doctorzeus
Member
Registered: 2011-12-24
Posts: 79

Re: Pacman Updated Package Logger Script

eschwartz wrote:

paclog --before 2021-02-03 | paclog --pkglist --logfile /dev/stdin

Gets you the name and version of every installed package at the given date. You can diff that with currently installed versions and/or match it up to versions in the cache.

...

This hook is matching Path and just greps the logfile. Why not match Package instead, and use NeedsTargets? Then pipe this output to pacman -Q - to get the versions of each of those packages and maybe translate them into filenames? Each output would then describe the state after the transaction, not before it, but then you could simply use the most recent log *before* the date you're trying to revert.

How do these downgrade logs handle trying to downgrade to something other than the latest upgrade? If you upgrade foo on Sunday and bar on Monday, and then on Tuesday you want to revert the "foo" update, you need to revert the "bar" update too. And sometimes foo and bar will be multiple updates to the *same* package.

Thanks! I'll probably look into editing based off that.

My big issue is at the moment is grouping the packages during an update. At the moment its done by the day however if I try and drill down to even the hour if the user starts an update at say 9:59:50 then it might register half the packages as upgraded in a different batch. Even in its current state if someone updates at midnight it runs the same risk (albeit mitigated).

Offline

#7 2021-02-11 12:53:50

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 649

Re: Pacman Updated Package Logger Script

doctorzeus wrote:

Does it have a way of directly generating the package file names in the cache without piping the contents of the log file?

No, it is just a general command line utility for quickly and succinctly showing you what upgraded and when. It is quite rare to have to downgrade packages and when you do you would typically only downgrade 1 or few packages anyhow. I.e. you look at what recently upgraded and manually downgrade one you pick may be the likely culprit. Then possibly repeat that a few times, retesting until the issue disappears. So it is essentially an iterative manual process and I only suggested my pkglog utility because it is a handy tool to aid that process.

Offline

#8 2021-02-11 14:24:31

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: Pacman Updated Package Logger Script

There's also ala-config in alatools. It uses the same approach as Trilby's script above so it doesn't track specific packages but it can be used to fully downgrade a system, e.g.

ala-config --date 2021-01-21 --sudo --pacman -Syuu

It can also install new packages from the same date which ensures their compatibility with the downgraded package versions on the system. It's particularly useful when you can't risk a system upgrade because you're on a deadline but you need a package that's been updated since your last upgrade.

edit
Just to be clear, I don't recommend using alatools to maintain a system in a non-upgraded state. It's really only for temporary circumstances in which you don't have time to deal with upgrade issues.

Last edited by Xyne (2021-02-11 14:27:06)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB