Presentation
Since yum version 3.2.25 (already available in RHEL 6), it is possible to play with a transaction history.
To start with, all package installation or removal operations are recorded in the rpmdb.
To display the rpmdb version, type:
# yum version Loaded plugins: fastestmirror, langpacks Installed: 7/x86_64 539:c8c53419da0ae4cba61f019df443d3c10593a208 Group-Installed: yum 14:d92850d928d628772a0a1d95c98e078545b0eea0 version
The information in bold represents the rpmdb version. If two servers have got the same rpmdb version, there are strictly identical from a yum point of view.
Transaction history
Then, it can be interesting to know which operations were previously done: it is the main purpose of the transaction history.
To get the last yum operation done, type:
# yum history info Loaded plugins: fastestmirror, langpacks Transaction ID : 12 Begin time : Mon Nov 10 11:28:01 2014 Begin rpmdb : 538:541464668d769a2bb7dbfc8337e305ab6db9fb47 End time : 11:28:03 2014 (2 seconds) End rpmdb : 539:c8c53419da0ae4cba61f019df443d3c10593a208 User : root Return-Code : Success Command Line : install setools-console Transaction performed with: Installed rpm-4.11.1-16.el7.x86_64 @anaconda Installed yum-3.4.3-118.el7.centos.noarch @anaconda Installed yum-plugin-fastestmirror-1.1.31-25.el7_0.noarch @updates Packages Altered: Install setools-console-3.3.7-46.el7.x86_64 @base history info
Here, you can see that the setools-console package was installed. You can also see the rpmdb version before and after the operation, the date, the time taken by the installation and the status of the operation (success/failure).
To get the list of all the previous yum recorded operations, type:
# yum history list all Loaded plugins: fastestmirror, langpacks ID | Login user | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 12 | root <root> | 2014-11-10 11:28 | Install | 1 11 | root <root> | 2014-11-01 06:22 | Install | 5 10 | root <root> | 2014-11-01 06:21 | Install | 7 9 | root <root> | 2014-11-01 06:04 | Install | 7 8 | root <root> | 2014-11-01 06:00 | Install | 5 7 | root <root> | 2014-10-29 17:12 | Install | 2 6 | root <root> | 2014-10-29 16:02 | Install | 9 5 | root <root> | 2014-10-29 15:39 | Install | 37 4 | root <root> | 2014-10-27 08:58 | Update | 14 3 | root <root> | 2014-10-16 10:01 | I, U | 47 2 | root <root> | 2014-09-05 15:32 | I, U | 49 1 | System <unset> | 2014-07-19 13:39 | Install | 464 history list
Note1: The Altered column represents the number of modified packages.
Note2: If you don’t specify the all option, you get the twenty most recent operations.
Note3: The yum history command reads the /var/log/yum.log file.
To get the details of one of these operations (here the operation called 9), type:
# yum history list 9 Loaded plugins: fastestmirror, langpacks ID | Command line | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 9 | install gcc | 2014-11-01 06:04 | Install | 7 history list
To get even more details about one of the operations (here the operation called 12), type:
# yum history info 12 Loaded plugins: fastestmirror, langpacks Transaction ID : 12 Begin time : Mon Nov 10 11:28:01 2014 Begin rpmdb : 538:541464668d769a2bb7dbfc8337e305ab6db9fb47 End time : 11:28:03 2014 (2 seconds) End rpmdb : 539:c8c53419da0ae4cba61f019df443d3c10593a208 User : root Return-Code : Success Command Line : install setools-console Transaction performed with: Installed rpm-4.11.1-16.el7.x86_64 @anaconda Installed yum-3.4.3-118.el7.centos.noarch @anaconda Installed yum-plugin-fastestmirror-1.1.31-25.el7_0.noarch @updates Packages Altered: Install setools-console-3.3.7-46.el7.x86_64 @base history info
To get the list of all the previous yum recorded operations organized by date, type:
# yum history summary Loaded plugins: fastestmirror, langpacks Login user | Time | Action(s) | Altered ------------------------------------------------------------------------------- root <root> | Last day | E, I | 3 root <root> | Last 2 weeks | Install | 72 root <root> | Last 3 months | I, U | 110 System <unset> | Last 6 months | Install | 464 history summary
Note: To get the list of all the previous package installations sorted per date, type:
# rpm -qa –last
To get all the operations concerning a specific package (here the kernel package), type:
# yum history list kernel Loaded plugins: fastestmirror, langpacks ID | Login user | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 3 | root <root> | 2014-10-16 10:01 | I, U | 47 2 | root <root> | 2014-09-05 15:32 | I, U | 49 1 | System <unset> | 2014-07-19 13:39 | Install | 464 history list
To get the details of the operations concerning a specific package (here the kernel package), type:
# yum history package-list kernel Loaded plugins: fastestmirror, langpacks ID | Action(s) | Package ------------------------------------------------------------------------------- 3 | Install | kernel-3.10.0-123.8.1.el7.x86_64 2 | Install | kernel-3.10.0-123.6.3.el7.x86_64 1 | Install | kernel-3.10.0-123.el7.x86_64 history package-list
Transaction history changes
In the transaction history expression, you can find the transaction term. This means that you can undo and redo each and every yum previously recorded operation, even though multiple packages were involved (you still have to be careful with glibc or selinux-policy packages that have very complicated dependencies).
To undo the last operation, type:
# yum history undo last Loaded plugins: fastestmirror, langpacks Undoing transaction 12, from Mon Nov 10 11:28:01 2014 Install setools-console-3.3.7-46.el7.x86_64 @base Resolving Dependencies --> Running transaction check ---> Package setools-console.x86_64 0:3.3.7-46.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: setools-console x86_64 3.3.7-46.el7 @base 1.1 M Transaction Summary ================================================================================ Remove 1 Package Installed size: 1.1 M Is this ok [y/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : setools-console-3.3.7-46.el7.x86_64 1/1 Verifying : setools-console-3.3.7-46.el7.x86_64 1/1 Removed: setools-console.x86_64 0:3.3.7-46.el7 Complete!
To display the transaction history concerning the setools-console package, type:
# yum history list setools-console Loaded plugins: fastestmirror, langpacks ID | Command line | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 13 | history undo last | 2014-11-10 18:12 | Erase | 1 12 | install setools-console | 2014-11-10 11:28 | Install | 1 history list
To re-install the setools-console package (the operation called 12), type:
# yum history redo 12
Use of rpm
To keep a clean history, you should avoid the use of the rpm command as much as possible because it breaks the transaction history.
For example, here is a transaction history:
# yum history Loaded plugins: fastestmirror, langpacks ID | Login user | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 2 | root | 2014-11-21 16:18 | I, U | 85 1 | System | 2014-11-21 14:14 | Install | 464 history list
A new package (here zlib-devel) is installed via the rpm command:
# rpm -ivh zlib-devel-1.2.7-13.el7.x86_64.rpm
Later on, a global package update is run:
# yum update ... Warning: RPMDB altered outside of yum. ...
Now, if we ask for the transaction history, we get:
# yum history Loaded plugins: fastestmirror, langpacks ID | Login user | Date and time | Action(s) | Altered ------------------------------------------------------------------------------- 3 | root | 2014-11-25 11:15 | I, U | 31 < 2 | root | 2014-11-21 16:18 | I, U | 85 > 1 | System | 2014-11-21 14:14 | Install | 464 history list
The < and > signs displayed show that some information has been lost (the package installed via the rpm command has no associated information).
There is no way to fix this problem. Your only option is to clear the transaction history and hide all the previous yum operations. To do that, type:
# yum history new
To avoid this problem, you can type:
# yum install zlib-devel or # yum install /path/to/zlib-devel-1.2.7-13.el7.x86_64.rpm
Transaction recovery
If during an upgrade your system goes down when restarted, type:
# yum-complete-transaction
This command searches for incomplete or aborted yum transactions on a system and attempts to complete them.
Source: RHEL 6 Deployment Guide.
Additional Resources
You can also watch Andrew Mallett‘s video about Yum History (2min/2016).
Leave a Reply
You must be logged in to post a comment.