• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 6,7 : How to use yum history to roll back a yum update

by admin

Note : Rollback of selinux, selinux-policy-*, kernel, glibc (dependencies of glibc such as gcc) packages to older version is not supported. Thus, downgrading a system to minor version (ex: RHEL6.6 to RHEL6.5) is not recommended as this might leave the system in undesired state. Use the yum history option for small update rollbacks.

How yum stores the transaction history

yum stores a sqlite database of information about each transaction. The history is organized terms of transaction ids and is updated every time a yum transaction affects the package configuration of the system. Mostly this database can be found in the /var/lib/yum/history/ directory. The “yum history” command allows the user to view the history of transactions. The following command lists the history of all transactions :-

# yum history list all

This will list the transaction ID along with the date and time, the actions performed and the number of packages altered. For more information on a particular transaction, note the transaction ID for that transaction and use it in the below command :

# yum history info [transaction_ID]

Rolling back a RPM uninstallation

Let us see an example of rolling back an uninstall of a package (firefox).
1. Check the previously installed version of firefox :

# rpm -qa | grep -i firefox
firefox-52.0-5.el7_3.x86_64         ======> Current version of rpm

2. Now Remove firefox package

# yum remove firefox

3. Now check all the past yum transactions using the command yum history:

# yum history
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    20 | root [root]              | 2017-05-24 09:48 | Erase          |    1    ====>  the firefox rpm removed here   
    19 | root [root]              | 2017-05-24 09:47 | I, U           |   14   
    18 | root [root]              | 2017-05-05 07:13 | Install        |    1  <
    17 | System [unset]           | 2016-12-27 16:46 | Update         |    2 > 
    16 | root [root]              | 2016-10-19 16:02 | Install        |    1  <
    15 | root [root]              | 2016-05-14 14:18 | Install        |    1 > 
    14 | root [root]              | 2016-05-14 13:52 | Install        |    4   
    13 | root [root]              | 2016-05-14 13:37 | Install        |    2   
    12 | root [root]              | 2016-05-14 13:35 | Install        |   88   
    11 | root [root]              | 2016-05-14 13:17 | Install        |    1   
history list

4. Now roll back the uninstall of the package using the yum history undo command. Note the transaction ID 20 of the firefox package uninstall transaction. The latest transactions are always at the top of the table.

# yum history undo 20
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Undoing transaction 20, from Wed May 24 09:48:41 2017
    Erase firefox-52.0-5.el7_3.x86_64 @BAVA
Resolving Dependencies
--> Running transaction check
---> Package firefox.x86_64 0:52.0-5.el7_3 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                      Arch                                        Version                                              Repository                                 Size
===============================================================================================================================================================================================
Installing:
 firefox                                      x86_64                                      52.0-5.el7_3                                         BAVA                                       83 M

Transaction Summary
===============================================================================================================================================================================================
Install  1 Package

Total download size: 83 M
Installed size: 150 M
Is this ok [y/d/N]: y
Downloading packages:
firefox-52.0-5.el7_3.x86_64.rpm                                                                                                                                         |  83 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : firefox-52.0-5.el7_3.x86_64                                                                                                                                                 1/1 
  Verifying  : firefox-52.0-5.el7_3.x86_64                                                                                                                                                 1/1 

Installed:
  firefox.x86_64 0:52.0-5.el7_3                                                                                                                                                                

Complete!

5. Above command Roll backed the previous transaction. You can check the firefox rpm now. You should get the exact same version which was installed previously.

# rpm -qa | grep -i firefox
firefox-52.0-5.el7_3.x86_64
Doing full system backup prior to any update is always recommended, and yum history is NOT meant to replace systems backups.

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. “lsb_release: command not found” – Fix in CentOS/RHEL
  2. code: Cross platform and extensible code editor
  3. pacman4console: command not found
  4. Linux “rm” Command Examples
  5. avifenc Command in Linux with Examples
  6. “docker compose” Command Examples
  7. tune2fs: command not found
  8. Rabbitmq install and management
  9. xz Command Examples in Linux
  10. fc-cache: Scan font directories to build font cache files

You May Also Like

Primary Sidebar

Recent Posts

  • gml2gv Command Examples
  • glow Command Examples
  • glib-compile-resources Command Examples
  • glances Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright