Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How would you Undo last packages installed?

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

How would you Undo last packages installed?

#1 Post by bester69 »

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:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: How would you Undo last packages installed?

#2 Post by bester69 »

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:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

L_V
Posts: 1477
Joined: 2007-03-19 09:04
Been thanked: 11 times

Re: How would you Undo last packages installed?

#3 Post by L_V »

Code: Select all

apt purge `tac /var/log/apt/history.log | grep Install | head -n1 | cut -d: -f2`

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: How would you Undo last packages installed?

#4 Post by bester69 »

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:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

L_V
Posts: 1477
Joined: 2007-03-19 09:04
Been thanked: 11 times

Re: How would you Undo last packages installed?

#5 Post by L_V »

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".

User avatar
wizard10000
Global Moderator
Global Moderator
Posts: 557
Joined: 2019-04-16 23:15
Location: southeastern us
Has thanked: 76 times
Been thanked: 85 times

Re: How would you Undo last packages installed?

#6 Post by wizard10000 »

Why wouldn't you just read apt's log?
we see things not as they are, but as we are.
-- anais nin

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: How would you Undo last packages installed?

#7 Post by bester69 »

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:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

User avatar
wizard10000
Global Moderator
Global Moderator
Posts: 557
Joined: 2019-04-16 23:15
Location: southeastern us
Has thanked: 76 times
Been thanked: 85 times

Re: How would you Undo last packages installed?

#8 Post by wizard10000 »

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
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: How would you Undo last packages installed?

#9 Post by bester69 »

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:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

Post Reply