Transactions and Rollback with Debian

6,255

Solution 1

I don't believe that there is such an option with aptitude or apt-get. However, aptitude keeps an excellent, clear log at /var/log/aptitude.You can use that to attempt rollbacks.

How well it will go will depend on the exact situation. If you merely want to remove a few packages you've installed, it should be trivial. But if you've upgraded (either because you follow testing or unstable or because you installed a security upgrade or point-release upgrade), then things are a bit more complicated. You can check if you still have the older .deb in your cache, or you can visit Debian snapshot.

If you don't use aptitude, you can poke around in dpkg's log (at /var/log/dpkg.log), but I find that a lot less friendly to work with.

Edit Now that I look at the article, there is one thing that is somewhat similar. You can get the state of your packages by doing this sequence. First get a list of the current package state:

dpkg --get-selections "*" > my_packages-datestamp

Then later you could rollback by using that package list:

dpkg --set-selections < my_packages-datestamp
apt-get -u dselect-upgrade

I've used this method to reinstall and then have exactly the current set of packages on the machine, and it's worked well. Again, though, how well it works will depend on what packages from the previous package list are available to you - either in your cache or in your repos.

Solution 2

There is no such option in dpkg or any apt related tool and there's a simple reason explaining this. Installing a package is not only unpacking files but also configuring them and this is done by running the pre/post installation/removal script associated to each package.

Restoring old files is easy but undoing what the postinst scripts have done is way more difficult. In theory dpkg supports the downgrade because it gives all the necessary information to the scripts so that they can detect when they're downgraded but in practice very few package implements that support properly (and Debian doesn't support downgrades officially).

Note however that for many simple packages that have no postinst script, the downgrade works very well. apt-get and aptitude can be used to force installation of older version with syntaxes like this:

aptitude install foo/testing # Downgrade a package to testing if you run unstable
aptitude install foo=1.2-3 # Downgrade to 1.2-3 if you run a higher version

So if you keep a note of all packages installed with their version, you can in most cases restore a previous state that works. You can also find out the versions previously installed by analzing dpkg's log /var/log/dpkg.log (or aptitude's log if you use only aptitude and not apt-get).

Share:
6,255

Related videos on Youtube

Coops
Author by

Coops

Updated on September 17, 2022

Comments

  • Coops
    Coops over 1 year

    I don't know if it is common knowledge, but RPM has support for rollbacking to a previous installation after performing an upgrade (which breaks something for instance). You can pass rpm the --repackage flag to generate a bunch of RPMs of files currently installed that it is going to change. You can then afterwards say "rpm -Uvh --rollback '2 hours ago'" and rollback your machine effortlessly to as it was 2 hours ago.

    My question is, has anyone found something similar in Debian-based distros?

    • cpl593x
      cpl593x almost 15 years
      BTW, the RPM rollback stuff is kinda buggy and unreliable. It has the inherent problem of the shell scripts in RPMs and the additional problem of neglect. And has been removed in RPM 4.6: rpm.org/wiki/Releases/4.6.0#Removedfeatures
  • Steve Schnepp
    Steve Schnepp almost 15 years
    This doesn't set the package version number though
  • Telemachus
    Telemachus almost 15 years
    @Steve: Right, which is why I said this: "Again, though, how well it works will depend on what packages from the previous package list are available to you - either in your cache or in your repos."