wesbarnett / snap-pac

Pacman hooks that use snapper to create pre/post btrfs snapshots like openSUSE's YaST
GNU General Public License v2.0
183 stars 14 forks source link

Feature request: use pacman.log to generate better snapshot description #17

Closed maximbaz closed 6 years ago

maximbaz commented 6 years ago

Today the script records pacman process name as a snapshot name, which works fine for installation (pacman -S xxx yyy), but is terrible for package upgrades, because it records only pacman -Syu without mentioning upgraded package names.

Actual result:

$ snapper list
...
pre  | pacman -Syu
post | pacman -Syu

I would argue that the need for snapshot recovery is more probable after an upgrade (e.g. of linux package) than after an installation of a package, but today it's difficult to see which snapshot among existing ones have been made before/after upgrading linux.

However, such information is actually available in /var/log/pacman.log:

[2018-02-01 12:29] [PACMAN] Running 'pacman -Syu'
[2018-02-01 12:29] [PACMAN] synchronizing package lists
[2018-02-01 12:29] [PACMAN] starting full system upgrade
[2018-02-01 12:29] [ALPM] running '00_snapper-pre.hook'...
[2018-02-01 12:29] [ALPM-SCRIPTLET] ==> root: 561
[2018-02-01 12:29] [ALPM] transaction started
[2018-02-01 12:29] [ALPM] upgraded jsoncpp (1.8.4-1 -> 1.8.4-2)
[2018-02-01 12:29] [ALPM] upgraded cmake (3.10.2-1 -> 3.10.2-2)
[2018-02-01 12:29] [ALPM] upgraded harfbuzz (1.7.4-1 -> 1.7.5-1)
[2018-02-01 12:29] [ALPM] upgraded fwupd (1.0.3-1 -> 1.0.4-1)
[2018-02-01 12:29] [ALPM] upgraded harfbuzz-icu (1.7.4-1 -> 1.7.5-1)
[2018-02-01 12:29] [ALPM] upgraded oniguruma (6.7.0-1 -> 6.7.1-1)
[2018-02-01 12:29] [ALPM] upgraded pyqt5-common (5.10-1 -> 5.10-2)
[2018-02-01 12:29] [ALPM] upgraded python-greenlet (0.4.12-1 -> 0.4.13-1)
[2018-02-01 12:29] [ALPM] upgraded python2-greenlet (0.4.12-1 -> 0.4.13-1)
[2018-02-01 12:29] [ALPM] installed python2-enum34 (1.1.6-1)
[2018-02-01 12:29] [ALPM] upgraded python2-pyqt5 (5.10-1 -> 5.10-2)
[2018-02-01 12:29] [ALPM] upgraded snapper (0.5.0-4 -> 0.5.4-1)
[2018-02-01 12:29] [ALPM] transaction completed
[2018-02-01 12:29] [ALPM] running 'gtk-update-icon-cache.hook'...
[2018-02-01 12:29] [ALPM] running 'systemd-update.hook'...
[2018-02-01 12:29] [ALPM] running 'update-desktop-database.hook'...
[2018-02-01 12:29] [ALPM] running 'update-mime-database.hook'...
[2018-02-01 12:29] [ALPM] running 'zy_snapper-post.hook'...

It should be possible to extract package names from the latest transaction.

To make things simple, I suggest to only extract package names, ignore information such as installed/upgraded or version. Thus:

Expected result:

$ snapper list
...
pre  | pacman -Syu
post | pacman: jsoncpp cmake harfbuzz fwupd harfbuzz-icu oniguruma pyqt5-common python-greenlet python2-greenlet python2-enum34 python2-pyqt5 snapper

Or actually, without even a pacman: prefix since it only consumes valuable space and I can look at the corresponding pre transaction for such info:

$ snapper list
...
pre  | pacman -Syu
post | jsoncpp cmake harfbuzz fwupd harfbuzz-icu oniguruma pyqt5-common python-greenlet python2-greenlet python2-enum34 python2-pyqt5 snapper
wesbarnett commented 6 years ago

I like the idea. I think it's been proposed before, but I can now change one line in the script to make this happen, so I will.

maximbaz commented 6 years ago

Wow this was extremely fast, thanks! Just tested, works perfectly, with install, upgrade and delete 👍