This tutorial will take you through creating an LVM snapshot. Suppose you have a NAS serving files for a company that operates 24 hours per day. There is no time you can stop the servers to run backups. Using LVM Snapshots, you can backup your company data any time of the day without the risk of file corruption or any noticeable interruption to the employees. There might be some performance degradation depending on your system specifications.
You must first have your local file-system configured with LVM2. If not, you can’t go forward with this tutorial.
Before we create the snapshot, take a look at my “/etc/fstab” below:
/dev/mapper/vg_agix-LogVol02 /home ext4 defaults 0 0 192.168.0.1:/backup /mnt/backup nfs defaults 0 0
The above shows two mounts. The top is the “/home” directory on the server which is an LVM partition. The bottom is my remote mount point for my backups to go to. Use “vgs” command to retrieve free space on Virtual Group. You must have more free space then can be used after with lvcreate -L
vgs VG #PV #LV #SN Attr VSize Vfree mapper 3 2 0 wz--n- 120.50g 30.00g
The following commands will backup /home to the remote mount location.
# Make sure the required directories exist mkdir /mnt/lvmsnapshot mkdir /mnt/backup # Mount the remote file system mount /mnt/backup # Create the snapshot facility lvcreate -L592M -s -n lvmsnapshot /dev/vg_agix/LogVol02 # Mount the snapshot mount -t ext4 /dev/vg_agix/lvmsnapshot /mnt/lvmsnapshot # Copy the data from the snapshot file system to the remote mount point rsync -rvp /mnt/lvmsnapshot/ /mnt/backup/ # Unmount the snapshot umount /mnt/lvmsnapshot # Remove the snapshot facility lvremove -f /dev/vg_agix/lvmsnapshot # Unmount the remote file system umount /mnt/backup
At this point the backup process is complete and the LVM is back as it was before we started.