Sunday, July 20, 2014

YUM fs-snapshoot

This functionality is very usefull. It can be used in case of if you want get back to previous os rpm stage. Let's imagine situation: you must update RedHat Enterprise server in your Company. Update has been successfully applied but application team is not satisfied from new OS packages. They foud issue and it turned out that there is a problem with some libraries. They are not compatible with currently installed application. In this case all indicates that in a short time you will must to recover the system from backup. I hope that you did that before starting OS update! If not you can be in trouble.

Now comes the useful package that will greatly facilitate our lives! Let's start:
  • installation - easy and simple one command:
    yum install yum-plugin-fs-snapshot

    Attention before you will start installation yum-plugin* (features) make sure that you have been enabled following repository:
  • post-installation steps:

    [rhel-6-server-optional-rpms]
    name = Red Hat Enterprise Linux 6 Server - Optional (RPMs)
    .
    ..
    ...
    enabled = 1
    ....
    .....
    ui_repoid_vars = releasever basearch
    At first you have to activate plugin in your  yum configuration. Till now each yum command revoke will load fs-snapshoot:

    Loaded plugins: aliases, changelog, downloadonly, fs-snapshot, kabi, product-id, refresh-packagekit, security, subscription-manager, tmprepo, verify, versionlock
    Enable plugin:

    Edit following file:
    /etc/yum/pluginconf.d/fs-snapshot.conf

    [main]
    enabled = 1
    exclude = /home /app01 /app02 /data /u01/cluster

    [lvm]
    enabled = 1
    # 'lvcreate_size_args' option must specify the snapshot LV size using -L or -l
    lvcreate_size_args = -l 25%ORIGIN


    [main] - this section is using to enable base functionality
    [lvm] - enabling lvm snapshoots

    lvcreate_size_args - determines how big compared in to the size of the original lv should be a snapshoot. Value is given in "%".


    exclude - may be usefull if you have some filesystems which should be excluded from lvm snapshoot list. Default settings treat to make snapshoot of all filesystems. In some case it can be not desirable. You can specify more than one filesystem by space delimiter.

    [root@hostname pluginconf.d]# yum update
    Loaded plugins: aliases, changelog, downloadonly, fs-snapshot, kabi, product-id, refresh-
                  : packagekit, security, subscription-manager, tmprepo, verify, versionlock
    This system is receiving updates from Red Hat Subscription Management.
    Loading support for Red Hat kernel ABI
    rhel-6-server-rpms                                                        | 3.7 kB     00:00    
    rhel-6-server-rpms/primary_db                                    |  27 MB     00:19    
    Setting up Update Process
    Resolving Dependencies
    Running transaction check
    Package e2fsprogs.x86_64 0:1.41.12-18.el6 will be updated
    Package e2fsprogs.x86_64 0:1.41.12-18.el6_5.1 will be an update
    Package e2fsprogs-libs.x86_64 0:1.41.12-18.el6 will be updated
    Package e2fsprogs-libs.x86_64 0:1.41.12-18.el6_5.1 will be an update
    Package grub.x86_64 1:0.97-83.el6 will be updated
    .
    ..
    ...

    Finished Dependency Resolution

    Dependencies Resolved

    ===========================================================
     Package                     Arch      Version                       Repository             Size
    ===========================================================
     kernel                      x86_64    2.6.32-431.23.3.el6           rhel-6-server-rpms     28 M
    Updating:
    .
    ..
    ...
    Transaction Summary
    =================================================================================================
    Install       1 Package(s)
    Upgrade      29 Package(s)

    Total download size: 145 M
    Is this ok [y/N]: y  
    Downloading Packages:
    (1/30): e2fsprogs-1.41.12-18.el6_5.1.x86_64.rpm                       | 553 kB     00:00 

    .
    ..
    ...
    (29/30): perf-2.6.32-431.23.3.el6.x86_64.rpm                              | 2.9 MB     00:02    
    (30/30): sos-2.2-47.el6_5.7.noarch.rpm                                          | 230 kB     00:00    
    -------------------------------------------------------------------------------------------------
    Total                                                            1.0 MB/s | 145 MB     02:19    
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
    fs-snapshot: WARNING: creating LVM snapshot of root LV.  If a kernel is
                          being altered /boot may need to be manually restored
                          in the event that a system rollback proves necessary.

    fs-snapshot: snapshotting / (/dev/vg_rhce01/lv_root): lv_root_yum_20140729224402
    .

    ..
    ...
      perf.x86_64 0:2.6.32-431.23.3.el6                                                             
      sos.noarch 0:2.2-47.el6_5.7                                                                   

    Complete!
  • checking if snapshoot has been successfully created:

    [root@hostname ~]# lvs -a -o name,devices
    Volume group vg_test03 is exported
    LV                                                                Devices       
    lv_root                                                         /dev/sda2(0)  
    lv_root_yum_20140729224402          /dev/sdb(0)
       

    lv_swap                                                       /dev/sda2(2178)

    We should choose 1 package from lists which was updated and remember version. After reboot we will restore system from lvm snapshoot!

    [root@hostname ~]# rpm -qa |grep nspr

    nspr-4.10.6-1.el6_5.x86_64
  • reboot server after upgrade OS
    [root@hostname ~]#
    reboot
  • restore operating system from snapshoot:
    [root@rhce01 ~]# lvconvert --merge /dev/vg_rhce01/lv_root_yum_20140729224402
      Can't merge over open origin volume
      Merging of snapshot lv_root_yum_20140729224402 will start next activation.
  • final reboot
    [root@hostname ~]# reboot
  • check if system has been restored

    [root@hostname ~]# lvs -a -o name,devices
    Volume group vg_test03 is exported
    LV                                                                Devices       
    lv_root                                                         /dev/sda2(0)    

    lv_swap                                                       /dev/sda2(2178)

    Snapshoot disappeared from lvm partition lists it mean that restore has successfully performed
  • final check:

    after upgrade:
    [root@hostname ~]# rpm -qa nspr
    nspr-4.10.6-1.el6_5.x86_64


    after restore:
    [root@hostname ~]# rpm -qa nspr
    nspr-4.10.2-1.el6_5.x86_64


    voilĂ 
    it works we returned to previous package constelation!
    Attention
    remember if update included kernel update you must choose valid kernel version via grub menu or apply changes permanently into /boot/grub/grub.conf!