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?
I don't believe that there is such an option with
aptitude
orapt-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 indpkg
'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:
Then later you could rollback by using that package list:
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.
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
andaptitude
can be used to force installation of older version with syntaxes like this: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 onlyaptitude
and notapt-get
).Sadly this is not something that either dpkg or apt is able to do. Debian packages aren't really meant to be downgraded and it isn't supported or tested. There certainly is no snapshotting support.
However, having said that, you can do it by hand. If you look in /var/log/dpkg.log, you'll find the log of operations that have happened. It's a little verbose, but you should be able to get the list of previous versions of packages that have been installed. Assuming they are still available in the repositories configured in your sources.list, you should be able to do:
If they are not available in the repo, you might still find them in /var/cache/apt/archives/ or you may be able to find them available for download somewhere, maybe in another repository. Once you have your list of packages, you can run:
You should then find you're back to the versions you had installed before. You may find that somethings are not the same, like configuration.
There is a method for having snapshots using LVM, but this is not particularly quick or easy to enable on an existing install. You would probably have to reinstall the system and set up your drives to use LVM. You can then create a LVM snapshot, do the upgrade, test it and then either remove the snapshot if you're happy or roll back to that snapshot if you're not. Obviously any data written since the snapshot will be removed as well as the packages.