Yum rollback – Yum history


Assume that, you are upgrading the package from x to y version, if that change cause anything critical then how can you rollback upgraded package to earlier version.

Yum have the feature of storing the history in /var/lib/yum/history/ directory. For this we need yum version in 3.2.xx, please execute the below command to check the yum version.

[root@server ~]# rpm -qa yum
yum-3.2.29-40.el6.centos.noarch

[root@server ~]# yum --version
3.2.29

Step 1: Check the previous yum history

[root@server ~]# yum history list
Loaded plugins: fastestmirror, refresh-packagekit, security
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
2 | root | 2015-04-27 15:31 | Install | 7 <
1 | System | 2015-03-24 15:04 | Install | 1470 >
history list

where,

ID – Transaction number
Login user – login session of user who performed the yum command

Suppose if you want the details about second trancation then below is the example.

[root@server ~]# yum history info 2
Loaded plugins: fastestmirror, refresh-packagekit, security
Transaction ID : 2
Begin time : Mon Apr 27 15:31:01 2015
Begin rpmdb : 1527:0254e77e4c65981112a81d88459092523c3b2df5
End time : 15:31:15 2015 (14 seconds)
End rpmdb : 1534:cc3b4857397a2458680e3567dd78a9cd7b081e8f
User : root
Return-Code : Success
Command Line : install mysql-devel
Transaction performed with:
Installed rpm-4.8.0-32.el6.x86_64 @anaconda-CentOS-201303020151.x86_64/6.4
Installed yum-3.2.29-40.el6.centos.noarch @anaconda-CentOS-201303020151.x86_64/6.4
Installed yum-plugin-fastestmirror-1.1.30-14.el6.noarch @anaconda-CentOS-201303020151.x86_64/6.4
Packages Altered:
Dep-Install keyutils-libs-devel-1.4-4.el6.x86_64 @cdrom
Dep-Install krb5-devel-1.10.3-10.el6.x86_64 @cdrom
Dep-Install libcom_err-devel-1.41.12-14.el6.x86_64 @cdrom
Dep-Install libselinux-devel-2.0.94-5.3.el6.x86_64 @cdrom
Dep-Install libsepol-devel-2.0.41-4.el6.x86_64 @cdrom
Install mysql-devel-5.1.66-2.el6_3.x86_64 @cdrom
Dep-Install openssl-devel-1.0.0-27.el6.x86_64 @cdrom
history info

Step 2: Yum rollback

The below command will rollback all your installed package to earlier stage.

[root@server ~]# yum history undo 2
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
cdrom | 4.0 kB 00:00 ...
Undoing transaction 2, from Mon Apr 27 15:31:01 2015
Dep-Install keyutils-libs-devel-1.4-4.el6.x86_64 @cdrom
Dep-Install krb5-devel-1.10.3-10.el6.x86_64 @cdrom
Dep-Install libcom_err-devel-1.41.12-14.el6.x86_64 @cdrom
Dep-Install libselinux-devel-2.0.94-5.3.el6.x86_64 @cdrom
Dep-Install libsepol-devel-2.0.41-4.el6.x86_64 @cdrom
Install mysql-devel-5.1.66-2.el6_3.x86_64 @cdrom
Dep-Install openssl-devel-1.0.0-27.el6.x86_64 @cdrom
Resolving Dependencies
--> Running transaction check
---> Package keyutils-libs-devel.x86_64 0:1.4-4.el6 will be erased
---> Package krb5-devel.x86_64 0:1.10.3-10.el6 will be erased
---> Package libcom_err-devel.x86_64 0:1.41.12-14.el6 will be erased
---> Package libselinux-devel.x86_64 0:2.0.94-5.3.el6 will be erased
---> Package libsepol-devel.x86_64 0:2.0.41-4.el6 will be erased
---> Package mysql-devel.x86_64 0:5.1.66-2.el6_3 will be erased
---> Package openssl-devel.x86_64 0:1.0.0-27.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Removing:
keyutils-libs-devel x86_64 1.4-4.el6 @cdrom 22 k
krb5-devel x86_64 1.10.3-10.el6 @cdrom 2.3 M
libcom_err-devel x86_64 1.41.12-14.el6 @cdrom 34 k
libselinux-devel x86_64 2.0.94-5.3.el6 @cdrom 158 k
libsepol-devel x86_64 2.0.41-4.el6 @cdrom 103 k
mysql-devel x86_64 5.1.66-2.el6_3 @cdrom 387 k
openssl-devel x86_64 1.0.0-27.el6 @cdrom 2.1 M

Transaction Summary
================================================================================
Remove 7 Package(s)

Installed size: 5.1 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : mysql-devel-5.1.66-2.el6_3.x86_64 1/7
Erasing : openssl-devel-1.0.0-27.el6.x86_64 2/7
Erasing : krb5-devel-1.10.3-10.el6.x86_64 3/7
Erasing : libselinux-devel-2.0.94-5.3.el6.x86_64 4/7
Erasing : libsepol-devel-2.0.41-4.el6.x86_64 5/7
Erasing : keyutils-libs-devel-1.4-4.el6.x86_64 6/7
Erasing : libcom_err-devel-1.41.12-14.el6.x86_64 7/7
Verifying : mysql-devel-5.1.66-2.el6_3.x86_64 1/7
Verifying : krb5-devel-1.10.3-10.el6.x86_64 2/7
Verifying : libsepol-devel-2.0.41-4.el6.x86_64 3/7
Verifying : keyutils-libs-devel-1.4-4.el6.x86_64 4/7
Verifying : openssl-devel-1.0.0-27.el6.x86_64 5/7
Verifying : libselinux-devel-2.0.94-5.3.el6.x86_64 6/7
Verifying : libcom_err-devel-1.41.12-14.el6.x86_64 7/7

Removed:
keyutils-libs-devel.x86_64 0:1.4-4.el6
krb5-devel.x86_64 0:1.10.3-10.el6
libcom_err-devel.x86_64 0:1.41.12-14.el6
libselinux-devel.x86_64 0:2.0.94-5.3.el6
libsepol-devel.x86_64 0:2.0.41-4.el6
mysql-devel.x86_64 0:5.1.66-2.el6_3
openssl-devel.x86_64 0:1.0.0-27.el6

Complete!

[root@server ~]# yum history list
Loaded plugins: fastestmirror, refresh-packagekit, security
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
3 | root | 2015-04-29 11:55 | Erase | 7
2 | root | 2015-04-27 15:31 | Install | 7 <
1 | System | 2015-03-24 15:04 | Install | 1470 >
history list