How to take LVM snapshot backup in LINUX

How to take LVM snapshot backup in LINUX

With the help of LVM snapshot backup we can freeze current state of an LVM volume. Making LVM snapshot backup make us to keep current state of volume and we can revert this state back if any needs arises during activity. A volume consists of two parts:  file system metadata and the actual blocks containing data in a file.

While creating LVM snapshot backup volume the file system metadata is copied to the newly created snapshot volume. The file blocks stay on the original volume, however, and as long as nothing has changed in the snapshot metadata, all pointers to the blocks on the original volume remain correct. When a file changes on the original volume, the original blocks are copied to the snapshot volume before the change is committed to the file system.

Scenario: For the demo of LVM snapshot backup , we have created one logical volume “etc_dup” in the volume group “myvg” and it been mounted on the mount point “/etc_dup” ,where we have copied sample /etc files using below command. To know more about creating volume click here.

So let’s start with LVM snapshot backup activity:

Step 1: Check overview of all volume group within system using vgs command.For our demo 50mb space is more than sufficient.

Step 2: Now create snapshot volume with size 50MB  in order to store the snapshot of mount point “/etc_dup”

In the above command:

Step 3: You can verify logical volume using below command. you can see that in the below output our newly created snapshot volume is listed.

Step 4: Create directory “/etc_dup_snap” for mounting the snapshot volume and mount the snapshot volume over it. Now if you go to “/etc_dup_snap” location and you can see same contents as that of the mount point “/etc_dup”.

Step 5: Now goto “/etc_dup” directory and remove all files within it using rm -f * command, don’t worry all our data is still intact in snapshot volume mount point “/etc_dup_snap”.

Now perform below list of step for merging the snapshot back to original volume which will revert back all data.

Step 6:  Merge the snapshot volume using below command.

You can safely ignore error message in the above output.

Step 7: Now unmount “/etc_dup” and “/etc_dup_snap”.

Step 8: Now deactivate and activate original volume. This step is necessary for merging the snapshot back into the original volume.

Step 9: Mount the “/etc_dup” mount point  and recheck its content using ll command as below:

You can see in the above output that all our original contents are back which means that we have successfully performed LVM snapshot backup activity.

NOTE: You don’t need to remove the LVM snapshot backup. By converting the snapshot back into the original volume, you have automatically removed the snapshot volume.

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!

Enjoyed this video?
How to take LVM snapshot backup in LINUX
"No Thanks. Please Close This Box!"