How would you Undo last packages installed?

Share your own howto's etc. Not for support questions!

How would you Undo last packages installed?

Postby bester69 » 2019-05-18 23:40

Hi,
I'd like to know a good way to rollback last installed packages in last days/hours.. so I dont have to reboot system to a snapshot everytime I decide to install just a few packages to test.

I found this way to remove all packages installed within last 3 days, but I suspect there're more interesting and properly ways to get this done.:
Code: Select all
find /var/lib/dpkg/info/ -name \*.list -mtime -3 | sed 's#.list$##;s#.*/##' | xargs sudo apt-get autoremove -y


So, How do you see this, is it right?, any other way to do it? :o
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1489
Joined: 2015-04-02 13:15

Re: How would you Undo last packages installed?

Postby bester69 » 2019-05-18 23:55

I also found this.
Code: Select all
date=2014-02-26
awk '$1=="Start-Date:" && $2=="'"$date"'" && got_date="yes" {}
  got_date=="yes" && $1=="Install:" && got_date="no" {
    for(i=2; i<=NF; i++) {
      if( $i !~ /,|\)/ && $(i+2) !~ /^automatic\)/ ) print $i } }' \
  /var/log/apt/history.log |
  xargs sudo apt-get -s remove

https://unix.stackexchange.com/question ... ecific-day

and this.:
https://github.com/rolfen/apt-history
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1489
Joined: 2015-04-02 13:15

Re: How would you Undo last packages installed?

Postby L_V » 2019-05-19 00:06

Code: Select all
apt purge `tac /var/log/apt/history.log | grep Install | head -n1 | cut -d: -f2`
L_V
 
Posts: 1125
Joined: 2007-03-19 09:04

Re: How would you Undo last packages installed?

Postby bester69 » 2019-05-19 01:47

L_V wrote:
Code: Select all
apt purge `tac /var/log/apt/history.log | grep Install | head -n1 | cut -d: -f2`



I did this to undo from <<mmin time>> installed packages

undo.sh <<time in minits>>
Code: Select all
#!/bin/bash
#
if [ -z "$1" ]
then
mmin="-2400"
else
mmin="-$1"
fi
#Último día

find /var/lib/dpkg/info/ -name \*.list -mmin "$mmin" | sed 's#.list$##;s#.*/##' | xargs sudo apt-get remove -s
read -p "Se Eliminaran los paquetes anteriores (y/n)?" choice
case "$choice" in
  y|Y )
  echo "yes"
  find /var/lib/dpkg/info/ -name \*.list -mmin "$mmin" | sed 's#.list$##;s#.*/##' | xargs sudo apt-get remove -y
  ;;
  n|N ) echo "no";;
  * ) echo "invalid";;
esac 
exit
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1489
Joined: 2015-04-02 13:15

Re: How would you Undo last packages installed?

Postby L_V » 2019-05-19 08:31

I don't clearly understand why you correlate package choice to be removed with "time", I miss the point.
Personally, I would prefer to have a clear visibility of what is going to be removed, and just let apt ask me for [Y/n] confirmation.
Code: Select all
for I in `tac /var/log/apt/history.log | grep Install | cut -d: -f2` ; do sudo apt remove $I ; done

... and just stop the process with "ctrl+c".
L_V
 
Posts: 1125
Joined: 2007-03-19 09:04

Re: How would you Undo last packages installed?

Postby wizard10000 » 2019-05-19 09:48

Why wouldn't you just read apt's log?
we see things not as they are, but as we are.
-- anais nin
User avatar
wizard10000
 
Posts: 102
Joined: 2019-04-16 23:15
Location: southeastern us

Re: How would you Undo last packages installed?

Postby bester69 » 2019-05-19 12:34

L_V wrote:I don't clearly understand why you correlate package choice to be removed with "time", I miss the point.
Personally, I would prefer to have a clear visibility of what is going to be removed, and just let apt ask me for [Y/n] confirmation.
Code: Select all
for I in `tac /var/log/apt/history.log | grep Install | cut -d: -f2` ; do sudo apt remove $I ; done

... and just stop the process with "ctrl+c".

Thanks a lot L_V

I liked a lot your method, that was more or less what I was looking for.. I didnt know about tac until now (thanks :o ), I think thats the key for this case. The only but I see, we cant uninstall dpkg's installed packages at the same time. I usually mix several common methods to install things: dpkg, apt's log (apt /aptitude/synaptic).
Last edited by bester69 on 2019-05-19 14:22, edited 6 times in total.
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1489
Joined: 2015-04-02 13:15

Re: How would you Undo last packages installed?

Postby wizard10000 » 2019-05-19 13:56

You should be able to get dpkg info from root's history and apt's log for everything else.

But - perhaps the thing to do would be to do the work before installing :)

I prefer to compile the stuff myself but snap/flatpak may also be an option. Worst case you can disassemble any .deb with a gooey archive manager, find out what its dependencies are, determine whether you can resolve them and if you can, install :)
we see things not as they are, but as we are.
-- anais nin
User avatar
wizard10000
 
Posts: 102
Joined: 2019-04-16 23:15
Location: southeastern us

Re: How would you Undo last packages installed?

Postby bester69 » 2019-05-19 14:23

wizard10000 wrote:You should be able to get dpkg info from root's history and apt's log for everything else.

But - perhaps the thing to do would be to do the work before installing :)

I prefer to compile the stuff myself but snap/flatpak may also be an option. Worst case you can disassemble any .deb with a gooey archive manager, find out what its dependencies are, determine whether you can resolve them and if you can, install :)

thanks Wizard



I made this script and to some more control, like installed dates and removing simulation.:

I used apt-log: http://mavior.eu/apt-log/

undo2.sh >>> LOVELY, LIKE A CHARM!! :o

Code: Select all
#!/bin/bash
#
tac /var/log/apt/history.log > /tmp/apt_history.log
while read -u 3 line
do
A=$(echo $line | grep Start-Date)
A=${A#*: }

if [ -z "$A" ]
then
:
else
I=$(sudo apt-log $A | grep Installed)
I=${I#*:   }

if [ -z "$I" ]
then
:
else
clear
echo "CON FECHA.: $A"
echo "**********************************************"
#echo "Paquetes a desinstalar: $I"
sudo apt-get remove -s $I
read -p "Se eliminarán los paquetes anteriores (y/n)?" choice
case "$choice" in
  y|Y )
 echo "yes"
 sudo apt-get remove  -y $I
  ;;
  n|N ) echo "no";;
  * ) echo "invalid";;
esac 
fi

fi

done 3< "/tmp/apt_history.log"
exit
bester69 wrote:You wont change my mind when I know Im right, Im not an ...
User avatar
bester69
 
Posts: 1489
Joined: 2015-04-02 13:15


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable