Header RSS Feed
 
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

Reverting/Restoring to a LVM snapshot as a rollback scenario
Tuesday - Jun 3rd 2014 - by - (0 comments)

LVM snapshots are a simple and fast way to "snapshot" the current file system. They are (probably) mainly used to create backups from the snapshot LV or to use the snapshot as backup itself.

But it can also be a huge time saver! I recently wanted to replace a manually installed Tomcat through the Debian packages. I knew that would change a lot of the current system (e.g. openjdk being used instead of Oracle JDK), I wanted to make sure I have a rollback.

The machine on which the Tomcat is installed is an LXC running on its own dedicated LVM file system. Before installing the tomcat7 packages, I took a LV snapshot:

lvcreate -L10g -s -n lxc12snapshot /dev/vgdata/lxc12
  Logical volume "lxc12snapshot" created

I then installed the packages in the LXC... to then realize that it breaks a lot of the current installation. I tried to remove all the packages with "apt-get remove" and "apt-get purge" but some configurations still remained:

apt-get purge tomcat7 tomcat7-admin tomcat7-common tomcat7-user openjdk-7-jdk

grep tomcat /etc/passwd
tomcat7:x:107:109::/usr/share/tomcat7:/bin/false

Instead of trying to manually clean up everything, I can use my fallback! Yay!

After halting the LXC in question, I first checked out the status of the current LV's:

lvs
LV        VG       Attr     LSize  Pool Origin    Data%  Move Log Copy%  Convert
lxc12snapshot vgdata swi-a-s- 10.00g   lxc12      4.80                       
lxc12   vgdata owi-aos-       20.00g 

Before the revert to the snapshot, the LV needs to be unmounted in case it is:

umount /var/lib/lxc/lxc12/rootfs

And then the rollback can happen (the snapshot will be merged with the current LV):

lvconvert --merge /dev/vgdata/lxc12snapshot
  Merging of volume lxc12snapshot started.
  lxc12: Merged: 4.8%
  lxc12: Merged: 3.4%
  lxc12: Merged: 1.4%
  lxc12: Merged: 0.0%
  lxc12: Merged: 0.0%
  Merge of snapshot into logical volume lxc12 has finished.
  Logical volume "lxc12snapshot" successfully removed

This took about 2 minutes.

I then remounted the LV and started the container.

mount /dev/mapper/vgdata-lxc12 /var/lib/lxc/lxc12/rootfs
lxc-start -n lxc12 -d -c /var/lib/lxc/lxc12/console.out

VoilĂ . Easy rollback which took only a couple of minutes.

 

Add a comment

Show form to leave a comment

Comments (newest first):

No comments yet.

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

6939 Days
until Death of Computers
Why?