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