Friday, October 3, 2014

How To Downgrade A Package In Red Hat Linux

------------------------------------------------------------------------------------------------------
 Downgrade A Package: Different Ways In RHEL   
------------------------------------------------------------------------------------------------------

Method 1: Using rpm -Uvh --oldpackage <CompletePackageName.rpm> Command

Method 2: Using yum downgrade Command.

Method 3: Using yum history in RHEL 6.x later.

Method 4: Manually un-install and install the required package (not a preferred way).




------------------------------------------------------------------------------------------------------------------------
 Method 1: Using rpm -Uvh --oldpackage <CompletePackageName.rpm> Command
------------------------------------------------------------------------------------------------------------------------
In this process we are going to downgrade "vsftpd" package. This has been tested on RHEL 6.2 virtual system.


- Current vsftpd package installed on the system:

[root@server3 Desktop]# rpm -qa|grep vsftpd
vsftpd-2.2.2-6.el6_2.1.x86_64  <------------------- Current vsftpd package version

- Now, to revert to the old vsftpd package, you would need to download that specific package and then to roll-back using command "rpm -Uvh --oldpackage" as shown here.

Details of the downloaded vsftpd package:

Download:     vsftpd-2.2.2-6.el6_0.1.x86_64.rpm (153,216 bytes
Build Date:     3/4/11 8:05:10 PM MVT

[root@server3 Desktop]# rpm -Uvh --oldpackage vsftpd-2.2.2-6.el6_0.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:vsftpd                 ########################################### [100%]

- Verify that the vsftpd package is rolled back to the previous version successfully:

[root@server3 Desktop]# rpm -qa|grep vsftpd
vsftpd-2.2.2-6.el6_0.1.x86_64  <------------------- Downgraded vsftpd package version


-------------------------------------------------------------------
 Method 2: Using Yum Downgrade Command
-------------------------------------------------------------------

-  Check the current vsftpd version:

[root@server3 vsft]# rpm -qa |grep vsftpd
vsftpd-2.2.2-11.el6.x86_64 <------------------- Current vsftpd package version

- Downgrading the package to the previous version:

[root@server3 Packages]# yum downgrade vsftpd
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
Setting up Downgrade Process
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-6.el6_2.1 will be a downgrade
---> Package vsftpd.x86_64 0:2.2.2-11.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved
================================================================================
 Package                         Arch                                Version               Repository                        Size
================================================================================
Downgrading:

 vsftpd                         x86_64                         2.2.2-6.el6_2.1             vsftpupdate                    149 k

Transaction Summary
================================================================================

Downgrade     1 Package(s)

Total download size: 149 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : vsftpd-2.2.2-6.el6_2.1.x86_64                                                                                                                       1/2
  Cleanup    : vsftpd-2.2.2-11.el6.x86_64                                                                                                                          2/2
Installed products updated.

Removed:
  vsftpd.x86_64 0:2.2.2-11.el6                                                                                                                                        

Installed:
  vsftpd.x86_64 0:2.2.2-6.el6_2.1                                                                                                                                     

Complete!

- Verify that the vsftpd package is rolled back to the previous version successfully.

[root@server3 Packages]# rpm -qa|grep vsftpd
vsftpd-2.2.2-6.el6_2.1.x86_64  <------------------- Downgraded vsftpd package version


----------------------------------------------------------------------
 Method 3: Using Yum History In RHEL 6.x Later
----------------------------------------------------------------------

Red Hat Enterprise Linux 6 includes "yum history" command variant using which we can roll back updates done via yum.


- Checking the currently installed "vsftpd" package version:

[root@server3 Desktop]# rpm -q vsftpd
vsftpd-2.2.2-11.el6.x86_64  <------------------- Current vsftpd package version

- First check by running "yum history" command to identify the yum instances and corresponding IDs:

[root@server3 Desktop]# yum history
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
ID     | Login user               | Date and time    | Action(s)      | Altered
----------------------------------------------------------------------------------------------
    13 | root <root>              | 2014-10-01 12:24 | Update         |    1  
    12 | root <root>              | 2014-09-30 23:58 | Update         |    1  
    11 | root <root>              | 2014-09-30 23:54 | Update         |    1  
    10 | root <root>              | 2014-09-28 12:54 | Update         |    1  
     9 | root <root>              | 2014-09-28 12:30 | Update         |    1  
     8 | root <root>              | 2014-09-28 12:27 | Install        |    3  
     7 | root <root>              | 2014-09-27 10:58 | Install        |   27  
     6 | root <root>              | 2014-09-25 13:00 | Install        |    1  
     5 | root <root>              | 2014-09-25 00:21 | Install        |    2  
     4 | root <root>              | 2014-09-06 12:20 | Install        |    1  
     1 | System <unset>           | 2014-08-31 17:19 | Install        |  911  
     3 | root <root>              | 2014-08-31 12:25 | Install        |    1  
     2 | root <root>              | 2014-08-31 12:24 | Install        |    1

- Next step is to run "yum history undo <ID>". Suppose, if you wish to revert the changes done most recently (yum update), then run this command as shown below:

- To know what was done (installed/updated/downgraded/removed) on a particular yum transaction, use the command "yum history info <ID>" 

[root@server3 Desktop]# yum history undo 13
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
Undoing transaction 13, from Wed Oct  1 12:24:55 2014
    Updated vsftpd-2.2.2-6.el6_2.1.x86_64 @vsftpupdate
    Update         2.2.2-11.el6.x86_64    @vsftpupdate
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-6.el6_2.1 will be a downgrade
---> Package vsftpd.x86_64 0:2.2.2-11.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved
================================================================================
 Package                     Arch                                Version                      Repository                        Size
================================================================================
 vsftpd                      x86_64                       2.2.2-6.el6_2.1                    vsftpupdate                    149 k

Transaction Summary
================================================================================

Total download size: 149 k
Is this ok [y/N]: y
Downloading Packages:

Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : vsftpd-2.2.2-6.el6_2.1.x86_64                                                                             1/2
  Cleanup    : vsftpd-2.2.2-11.el6.x86_64                                                                                2/2
Installed products updated.

Removed:
  vsftpd.x86_64 0:2.2.2-11.el6                                                                                              

Installed:
  vsftpd.x86_64 0:2.2.2-6.el6_2.1                                                                                           

Complete!

- Check if the yum roll back is successful. In this case we've reverted the "vsftpd" package upgrade, so lets test the current package version now:

[root@server3 Desktop]# rpm -q vsftpd
vsftpd-2.2.2-6.el6_2.1.x86_64  <------------------- Downgraded vsftpd package version

----------------------------------------------------------------------
Downgrading Package Along With Dependency
----------------------------------------------------------------------
>> If you are planning to downgrade a package which has dependency then need to downgrade the dependant package as well to the correct version, otherwise, downgrade doesn't work. Say, you wish to downgrade httpd, so the dependent packages for this are "httpd-tools" and "mod_ssl", hence, you would need to downgrade all of them together.

Example: Installed httpd and its dependent packages on a system are as shown below:

[root@server3 oldhttp]# rpm -qa|egrep "httpd|mod_ssl"
httpd-tools-2.2.15-28.el6_4.x86_64 <------------------- Current httpd package and its dependencies
httpd-2.2.15-28.el6_4.x86_64
mod_ssl-2.2.15-28.el6_4.x86_64

Now, we need to downgrade httpd to the version "2.2.15-15.el6", so, we need to download all these three packages of this version available and then we could downgrade httpd as shown below:

[root@server3 oldhttp]# yum downgrade httpd-2.2.15-15.el6 httpd-tools-2.2.15-15.el6 mod_ssl-2.2.15-15.el6
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
Setting up Downgrade Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-15.el6 will be a downgrade
---> Package httpd.x86_64 0:2.2.15-28.el6_4 will be erased
---> Package httpd-tools.x86_64 0:2.2.15-15.el6 will be a downgrade
---> Package httpd-tools.x86_64 0:2.2.15-28.el6_4 will be erased
---> Package mod_ssl.x86_64 1:2.2.15-15.el6 will be a downgrade
---> Package mod_ssl.x86_64 1:2.2.15-28.el6_4 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                     Arch                            Version                         Repository                        Size
================================================================================
 httpd                       x86_64                        2.2.15-15.el6                      oldhttp                             808 k
 httpd-tools              x86_64                       2.2.15-15.el6                      oldhttp                              70 k
 mod_ssl                  x86_64                       1:2.2.15-15.el6                    oldhttp                              87 k

Transaction Summary
================================================================================
Downgrade     3 Package(s)

Total download size: 964 k
Is this ok [y/N]: y
Downloading Packages:
---------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   95 MB/s | 964 kB     00:00    
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : httpd-tools-2.2.15-15.el6.x86_64                                                                                                                    1/6
  Installing : httpd-2.2.15-15.el6.x86_64                                                                                                                          2/6
  Installing : 1:mod_ssl-2.2.15-15.el6.x86_64                                                                                                                      3/6
  Cleanup    : 1:mod_ssl-2.2.15-28.el6_4.x86_64                                                                                                                    4/6
  Cleanup    : httpd-2.2.15-28.el6_4.x86_64                                                                                                                        5/6
  Cleanup    : httpd-tools-2.2.15-28.el6_4.x86_64                                                                                                                  6/6
Installed products updated.

Removed:
  httpd.x86_64 0:2.2.15-28.el6_4                      httpd-tools.x86_64 0:2.2.15-28.el6_4                      mod_ssl.x86_64 1:2.2.15-28.el6_4                    

Installed:
  httpd.x86_64 0:2.2.15-15.el6                        httpd-tools.x86_64 0:2.2.15-15.el6                        mod_ssl.x86_64 1:2.2.15-15.el6                      

Complete!

- Verify the package version now:

[root@server3 oldhttp]# rpm -qa|egrep "httpd|mod_ssl"
httpd-tools-2.2.15-15.el6.x86_64    <------------------- Downgraded httpd package and its dependencies
httpd-2.2.15-15.el6.x86_64
mod_ssl-2.2.15-15.el6.x86_64


NOTE: For all the above methods, dependency must need to be satisfied, so dependent packages also gets downgraded to most recent available or else gets removed if there is no downgraded version available.
Note: Click on this link to know more about "Problems with performing downgrades".

A good information about "yum history" command variants are documented here: https://www.certdepot.net/rhel7-use-yum-transaction-history/

No comments: