Is there a way, before starting an aptitude upgrade
or apt-get upgrade
, to set up something so that you can "easily" rollback your system to the "apt" state it was before the actual upgrade, if something goes wrong?
That is, for example, reinstall the old version of the packages that were upgraded during the process.
(EDIT) A few hints: I know that etckeeper
for example uses some hook on apt
so that it is notified whenever apt
installs or uninstalls a package. I suppose there could be some kind of script that could save the list of newly installed package and their previous version number to be able to reinstall them from the apt
cache (/var/cache/apt/archives
). There is also checkinstall
which can keep track of file modifications…
Any details on how to achieve that properly?
Best Answer
I just now had to figure out an answer to this, because the last
apt-get upgrade
on a Debian server made it impossible to boot the most recent kernel beyond a busybox, failing to mount the zfs root partition. At least an older kernel could still boot, but was incompatible with other software. Thus the need for a rollback.The short answer - you could use the following command:
if it does what you want remove the
-s
and run it again. Here are the steps I took to get this working properly:I temporarily trimmed my
/var/log/dpkg.log
to leave just today's upgradeI installed the tiny script
apt-history
from here into~/.bashrc
and ranThis provides a nicely formatted list of versioned packages to roll-back to by feeding it into
apt-get install
. Trim this list as needed in a text editor and then run (with-s
for dry-run first):Apt will warn about the downgrades which is expected. To prevent this rollback to be overwritten by the next upgrade, the packages will need to be pinned, until the original issue is resolved. For example with:
apt-mark hold zfsutils libzfs2 ...