Friday, June 28, 2013

RHEL4 or an old Linux but you want to roll back a LVM snapshot

LVM has supported snapshot since long time ago but it is so recent ( 2-3 years) since merge support is introduced in RHEL6 which means you can roll back to the snapshot points. Before this, I think snapshots were only a solution when it was needed to freeze a filesystem to be backed up.

Well ... what about an old kernel which only knows how to snapshot but not to merge !?

Easy, boot the system with a kernel which knows how to do this. like, booting from a RHEL6 DVD in rescue mode. LVM is a LVM anyway.

Or, you can dd the snapshot device file to an equally sized disk to create an equivalent filesystem to the snapshot.

OK ... to show you how, follow the following guidelines:

1. Create a snapshot:
There should be enough free space in the VG for the snapshot. It was nice if you could use other VGs to host the snapshot LV, but this feature is not available. Add a need disk to the VG to make some room if you need to.


#lvcreate -L<size> -s -n LogVol00-backup

 2.Do changes
Cool, now you have the snapshot. Do your changes

3.Clean up
If it went well, remove the snapshot LV and release the disk:

#lvremove LogVol00-backup

3-1. If you are on RHEL6 or a new version or a high end kernel:

#lvconvert --merge LogVol00-backup

If your KVs are mounted nothing will happen unless you reboot or unmount, deactivate and reactivate the LV.

#umount /mountpoint
#lvchange -an LogVol00-backup
#lvchange -ay LogVol00-backup
#mount /mountpoint

 Obviously  you can't do this if your LV id the root partition. Just reboot if you are stuck.

3-2. What if your OS does not support  merge ? Boot from a RHEL6 DVD and go into rescue mode and feel free to do the step3.

Or, alternatively, add a disk or create a LV equally sized to the original LV and do the following:

dd if=/dev/MV/snapshot_lv of=/dev/DV/DestinationLV

It will generate an LV with the contents of the snapshot LV. Don't be scared of dd. You know what you are doing, aren't you ?






 

No comments: