Pages

Sunday, October 7, 2018

Linux - Rolling Back a Yum Update


One of the most important task of linux system admin is to update packages on the server using the yum command.  There can times where we apply some updates and it wont go well. During these time we need to rollback the things that we did.

In this article we will see how we can rollback changes done using the yum command in linux

1. Let's start by installing a sample package like httpd using the “yum install -y httpd

2. Now linux provides us a yum history command by which we can see all the things that are done using the “yum” command. Run
[root@testing-machine vagrant]# yum history list all
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
ID     | Login user                    | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    11 | vagrant         | 2018-10-06 17:35 | Install        |    5  
    10 | vagrant         | 2018-10-05 01:41 | Install        |   32  
     9 | vagrant         | 2018-10-04 23:41 | Update         |    3  
     8 | vagrant         | 2018-09-28 02:18 | I, U           |   24  
     7 | vagrant         | 2018-09-27 14:18 | Install        |    6  
     6 | vagrant         | 2018-09-27 13:11 | Install        |    1  
     5 | vagrant         | 2018-09-27 13:11 | Install        |    1  
     4 | vagrant         | 2018-09-27 13:08 | I, U           |   39  
     3 | vagrant         | 2018-09-27 13:06 | Install        |    1  
     2 | vagrant         | 2018-09-27 13:04 | Install        |    1  
     1 | System            | 2018-05-12 18:50 | Install        |  306  
history list

We can see all the list of actions done, user who performed that and also data and time.

3. Check the info for the ID. In this case we are checking the info for 11 id
[root@testing-machine vagrant]# yum history info 11
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Transaction ID : 11
Begin time     : Sat Oct  6 17:35:41 2018
Begin rpmdb    : 402:d85edbcc64c156cc175bcba841efdfc493d23d6e
End time       :            17:35:43 2018 (2 seconds)
End rpmdb      : 407:4506ee26c91c1072acac7a7e9d3b0a0b0690a1b4
User           : vagrant
Return-Code    : Success
Command Line   : install httpd -y
Transaction performed with:
    Installed     rpm-4.11.3-32.el7.x86_64                      @anaconda
    Installed     yum-3.4.3-158.el7.centos.noarch               @anaconda
    Installed     yum-metadata-parser-1.1.4-10.el7.x86_64       @anaconda
    Installed     yum-plugin-fastestmirror-1.1.31-45.el7.noarch @anaconda
Packages Altered:
    Dep-Install apr-1.4.8-3.el7_4.1.x86_64               @base
    Dep-Install apr-util-1.5.2-6.el7.x86_64              @base
    Install     httpd-2.4.6-80.el7.centos.1.x86_64       @updates
    Dep-Install httpd-tools-2.4.6-80.el7.centos.1.x86_64 @updates
    Dep-Install mailcap-2.1.41-2.el7.noarch              @base
history info

4. Once we are sure that the ID belongs to the changes that we did, we can rollback that change using,
[root@testing-machine vagrant]# yum history undo 11
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Undoing transaction 11, from Sat Oct  6 17:35:41 2018
    Dep-Install apr-1.4.8-3.el7_4.1.x86_64               @base
    Dep-Install apr-util-1.5.2-6.el7.x86_64              @base
    Install     httpd-2.4.6-80.el7.centos.1.x86_64       @updates
    Dep-Install httpd-tools-2.4.6-80.el7.centos.1.x86_64 @updates
    Dep-Install mailcap-2.1.41-2.el7.noarch              @base
Resolving Dependencies
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be erased
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be erased
---> Package httpd.x86_64 0:2.4.6-80.el7.centos.1 will be erased
---> Package httpd-tools.x86_64 0:2.4.6-80.el7.centos.1 will be erased
---> Package mailcap.noarch 0:2.1.41-2.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================
 Package             Arch           Version                        Repository        Size
==========================================================================================
Removing:
 apr                 x86_64         1.4.8-3.el7_4.1                @base            221 k
 apr-util            x86_64         1.5.2-6.el7                    @base            194 k
 httpd               x86_64         2.4.6-80.el7.centos.1          @updates         9.4 M
 httpd-tools         x86_64         2.4.6-80.el7.centos.1          @updates         169 k
 mailcap             noarch         2.1.41-2.el7                   @base             62 k

Transaction Summary
==========================================================================================
Remove  5 Packages

Installed size: 10 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : httpd-2.4.6-80.el7.centos.1.x86_64                                     1/5
  Erasing    : httpd-tools-2.4.6-80.el7.centos.1.x86_64                               2/5
  Erasing    : mailcap-2.1.41-2.el7.noarch                                            3/5
  Erasing    : apr-util-1.5.2-6.el7.x86_64                                            4/5
  Erasing    : apr-1.4.8-3.el7_4.1.x86_64                                             5/5
  Verifying  : mailcap-2.1.41-2.el7.noarch                                            1/5
  Verifying  : httpd-2.4.6-80.el7.centos.1.x86_64                                     2/5
  Verifying  : httpd-tools-2.4.6-80.el7.centos.1.x86_64                               3/5
  Verifying  : apr-1.4.8-3.el7_4.1.x86_64                                             4/5
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                            5/5

Removed:
  apr.x86_64 0:1.4.8-3.el7_4.1             apr-util.x86_64 0:1.5.2-6.el7                
  httpd.x86_64 0:2.4.6-80.el7.centos.1     httpd-tools.x86_64 0:2.4.6-80.el7.centos.1   
  mailcap.noarch 0:2.1.41-2.el7          

Complete

This is how we rollback a Yum update. More to Come, Happy learning :-)


No comments :

Post a Comment