Re Undoing an update

Jack quiet_celt at yahoo.com
Sat Jan 31 10:52:34 CST 2009


--- On Fri, 1/30/09, Christofer C. Bell <christofer.c.bell at gmail.com> wrote:

> From: Christofer C. Bell <christofer.c.bell at gmail.com>
>
> Craig wants to roll back updates, not restore a list of
> package selections.
> He wants to go back to the versions of software that were
> on his system
> previous to the update.  A list of package selections will
> not do this.

Right, my bad. I was missing a step.
Here's a corrected version.

------------------------------------------------------------
To save your installed list do this:

dpkg --get selections | grep -v deinstall > packagestateXXXXXXXX.txt
cp /var/lib/dpkg/available > availableXXXXXXXX.bak

where XXXXXXXX is the current date. Or use your own convention.
The grep -v deinstall removes entries of packages that are marked for removal.

===============================================================

To later restore them do this:

dpkg --clear-selections
dpkg --set-selections < packagestateXXXXXXXX.txt
cp availableXXXXXXXX.bak > /var/lib/dpkg/available

apt-get -u dselect-upgrade --purge

----------------------------------------------------------------


I'm not sure this will even work, because what really needs to be done here is a "dpkg --force-downgrade <package>" for each package that needs to be downgraded. Not to mention that the /var/lib/dpkg/status file lists the current state. Another possibility is to copy the status file also, and then use the grandparent version of that to try to fool dpkg into thinking that an even earlier version is installed than really is. I didn't include this trick, because it's inherently extremely dangerous to the state of your system. here are some other tricks that could be pulled, but it only gets more dangerous from here. Here there be monsters.

Of course, the truly correct way to do this is to record which packages are being upgraded every time and then feed this list into a "dpkg --force-downgrade <package>" command. However, the problem here is that dpkg performs NO dependency checking when doing this. So unless you know what packages were actually upgraded and make sure to downgrade them all, you could really hose your system. This is debian's Achilles heel. There is simply no safe route to a downgrade. What debian needs is a "state history" and a "restore state" feature.


So, assuming you have the list of the packages you need to downgrade, and you feel comfortable doing dangerous things to your OS and you have a really good and recent backup, here's one primitive way that I know WILL do it.

Copy and paste the lines between the dashes and save into a file dpkgundo.sh, and make it executable (chmod 700 dpkgundo.sh).
---------------------------------------------------------------------
#/bin/bash

# minimal sanity check for both arguments.
if [ $# <> 2 ]
then
echo "Usage :$0 <dpkg available list to restore> <file with list of packages to restore>"
exit 1
fi

# First restore the available versions list.
# WARNING: Assumes the /etc/apt/sources.list has not been updated since the last update
cp $1 > /var/lib/dpkg/available

# Next let's restore the packages
cat $2 | xargs dpkg --force-downgrade
# for interactive processing comment out the above line and uncomment the following line
#cat $2 | xargs -p dpkg --force-downgrade
----------------------------------------------------------------

To execute type on the commandline "./dpkgundo.sh /path/to/availableXXXXXXXX.bak /path/to/downgradelist.txt"

This only works if you have a history of the debian available packages file. This won't help Craig.


But this will:

Copy and paste the lines between the dashes and save into a file dpkgdowngrade.sh, and make it executable (chmod 700 dpkgdowngrade.sh).
---------------------------------------------------------------------
#/bin/bash

# minimal sanity check for both arguments.
if [ $# <> 2 ]
then
echo "Usage :$0 <directory with packages to restore> <file with list of packages to restore>"
exit 1
fi

#Let's go to the directory with the packages to restore
cd $1

# Next let's restore the packages
cat $2 | xargs dpkg --force-downgrade
# for interactive processing comment out the above line and uncomment the following line
#cat $2 | xargs -p dpkg --force-downgrade
----------------------------------------------------------------

To use this script, first build the list of packages you want to restore and save it to a file. You will need the actual names of the packages for this (ex: zenity_2.22.1-1_i386.deb). Then you will need to find and download them to a directory. Finally run the script like this:
./dpkgdowngrade.sh <directory with packages to restore> <file with list of packages to restore>

Remember, I consider this to be very dangerous stuff and it could potentially frak your system. No guarantee is provided and if your computer explodes in a cataclysmic supernova as a result I take no responsibility for it. Debian simply doesn't support downgrading. Why would you ever downgrade, debian package maintainers are perfect and never make mistakes?

Brian J




More information about the Kclug mailing list