Friday, October 3, 2014

How To Downgrade A Package In Red Hat Linux?


--------------------------------------------------------------------------------------------------------
Downgrade A Package: Different Ways In Red Hat Enterprise Linux
--------------------------------------------------------------------------------------------------------

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

Method 2: Using "yum downgrade <PackageName>" Command.

Method 3: Using "yum history undo/rollback" in RHEL 6 & later.

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


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

Let's demonstrate this method now. I'm going to use the 'vsftpd' package for reference here. This has been tested on RHEL 6.2 virtual system.


- Verify the 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

- To revert to the old vsftpd package,  one has to download that specific package and then roll-back can be done using command "rpm -Uvh --oldpackage" as shown below:

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' package 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 & Later
--------------------------------------------------------------------------

In RHEL 6.x and above versions one could use "yum history" command to roll back the changes or updates done and which would go back to the previous state whichever is available. Let's see how we could get this done now:

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

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

- So, let's roll back changes done (update) done by 'yum' command using 'yum history undo <ID>" as shown below:

[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 dependent package as well to the correct version, otherwise, downgrade doesn't work. Suppose if there is a requirement to downgrade 'httpd' package then all the dependent packages would also need a downgrade.

- Check the installed httpd and its dependent packages on a system.

[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, to downgrade httpd to the version "2.2.15-15.el6", we need to download all these three packages of this version and then downgrade could be processed as demonstrated 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                  70k
mod_ssl               x86_64                    1:2.2.15-15.el6               oldhttp                  87k

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.

A good information about "yum history" command variants are documented at this site:

https://www.certdepot.net/rhel7-use-yum-transaction-history/

1 comment:

Anonymous said...

Thanks for the detailed steps with all the possible alternatives. Most of these alternatives seem to be manual, either we need to see the history and provide transaction id or check what are the dependencies and then provide those as input. If we need to automate it like in Ansible playbook how to do the downgrade or rollback without manual intervention?