How To Backup And Restore LVM On openSUSE 42.1

How To Backup And Restore LVM On openSUSE 42.1

Today, we will go through how we can Backup And Restore LVM On openSUSE 42.1 Linux distribution. Let’s start then.

What is LVM ?

LVM stands for Logical Volume Management. It is a dynamic system of managing logical volumes, or filesystems, that is much more advanced, flexible and scalable than the traditional method of partitioning a hard disk drive into one or more drives. Heinz Mauelshagen wrote the original LVM code back in 1998 for Linux driven kernel. Logical Volume Manager provides  a layer of abstraction between your operating system and the disks/partitions you have. You can  consider it as a software layer on top of all the hard disk drives and partitions that you have, which creates an abstraction of continuity gives you the freedom for managing hard drive replacement, re-partitioning, resizing, backup and restore. It is a device mapper that can provides logical volume management for the Linux kernel. Most modern Linux distributions are capable with the LVM features. LVM can Manages large hard disk farms by allowing disks to be added and replaced without downtime or service disruption for resizing. So, it  allows you to resize your disk size later as per your requirements.

It can create a single logical volume from multiple physical volumes or even from entire hard disk which allows you dynamic volume resizing. Historically, a partition size is static, right? You can not reduce or increased its size. But not with LVM. It take storage units from multiple drives and then pooled into a “logical volume”, and  then it can be allocated to partitions. Additionally, units can be added or removed from partitions as per your space requirements.

There are 3 components of LVM and they are “Volume Groups”, “Physical Volumes” & “Logical Volumes”. A Volume Group is a name with a  collections of physical and logical volumes. Physical Volumes are correspond to disks and  they are mostly block devices that provide the space to store logical volumes. Logical volumes are correspond to disk partitions with a filesystem type.

Why use LVM?

Think of your LVM volumes as “dynamic partitions”, meaning that you can create, resize, delete all of your LVM “partitions” normally known as  “Logical Volumes”  from the command line by using terminal. Even You don’t need to reboot your server to make the kernel aware of the newly-created or resized partitions. Also, if you have more than one hard disk drive, logical volumes can extend over more than one disk size that is they are not limited by the size of one single disk, rather by the total aggregate size of all of your hard disk drive. You can create a read-only snapshot of any Logical Volumes. This is a great feature for server data backup.

Prerequisites

You must have LVM volumes on your system. Here, I am not covering how you can create LVM volumes. I am hoping that you know how to do that.

Backup & Restore LVM

A LVM snapshot is an exact mirror copy of an LVM partition which has all the data from the LVM volume from the time that snapshot was created. The main advantage of LVM snapshots is that they can reduce the amount of time cause a LVM snapshot is usually created in fractions of a second.

Before start for a snapshot, let’s have a look at your system. To do so, open a terminal and issue these following command one after another.

 sudo pvdisplay
sudo vgdisplay
sudo lvdisplay
sudo fdisk -l

With these above commands, you will know everything that you will need to start the backing procedure. All LVM partition will show 8e for their Id.

Let’s do a LVM backup. Now it’s time to create the snapshot of the /dev/server1/root volume. We will call the snapshot “homesnapshot”. To do so, issue the below command

sudo lvcreate -L10G -s -n homesnapshot /dev/server1/root

Where s stands for snapshot and n stands for name.

Note: If the snapshot logical volume becomes full it will be dropped so it is very important to allocate enough space for it. So make sure of it please. The size of the snapshot has to be greater than the original data size.

To extend the snapshot size automatically, we can do this by using some modification in /etc/lvm/lvm.conf file. Open /etc/lvm/lvm.conf file with your favourite file editor and look or search for the word “autoextend”. Change your numerical values accordingly and then save & exit from the file.

Now type the following command in the terminal and see the output again.

sudo lvdisplay

You will see something like this

LV snapshot status     source of
                         /dev/server1/homesnapshot [active]
  LV Status              available

Now, let’s mount the newly created snapshot.

We want to mount /dev/server1/homesnapshot on /snapshots folder. So, first we need to create that directory by:

sudo mkdir /snapshots

Then, we mount it by using the following command in the terminal.

sudo mount /dev/server1/homesnapshot /snapshots

So, our snapshot has been successfully created and mounted.

Now, we can create a backup of the snapshot as well.

sudo tar -pczf backup.tar.gz /snapshots

For the above command, you are making a gunzip file archive of the folder “snapshots” by using tar command and the name of the tar archive is backup.tar.gz. You can maintain a date wise naming convention for thebackup.tar.gz file while you are archiving.

Remove LVM Snapshot

To remove the snapshot, we need to unmount it first. To do so,

sudo umount /snapshots

To check for the mount point whether it is properly unmounted, issue the below command in the terminal.

sudo df -h

Now, issue this on your terminal

sudo lvremove /dev/server1/root

This will remove the snapshot logical volume from the system.

Thanks for reading. That’s all for today. Have a great day.

Leave a Reply

Your email address will not be published. Required fields are marked *