Clone and Compress LVM Volume to Disk Image
Clone and Compress LVM Volume to Disk Image
If you need to backup an LVM volume, you can do so by first turning off the virtual machine that is using the volume, and then you can use the dd and gzip utilities to create a copy of the volume to an .img file and compress the image file. This compressed image file can then be transferred remotely over SSH or HTTP (for fastest results) to another server where it can be restored.
Need More Storage Space for the Backup Image (Optional)?
If you don't have enough storage space on the root LVM volume the main system uses on the host server to handle saving the backup image file to, you can always create a new LVM and then mount it on the host LVM file system to save it there.
These steps are optional:
1. Create new hard drive in your vm pool using virt-manager and name it temp_storage – you don't need to setup the OS or continue creating the virtual machine
2. Format and mount this new LVM volume (update vms with your pool's actual name – on my server, it is named vms):
mkfs.ext4 /dev/mapper/vms-temp_storage mount /dev/mapper/vms-temp_storage /mnt/store
Copy and Compress the LVM
Use the below commands to copy your LVM volume to an img file. Update the names and the paths as needed.
dd if=/dev/vms/name_of_lvm of=/mnt/store/name_of_lvm.img bs=8M status=progress gzip name_of_lvm.img -1
Uncompressing and Restoring the LVM
Just decompress the image file and then use the dd command to restore the image to the LVM volume created on the target or restore server.
gunzip name_of_lvm.img.gz dd if=name_of_lvm.img of=/dev/vms/restore-lvm-name bs=8M status=progress
And you're done 🙂
Rent dedicated game servers from Chicago, Kansas City, Dallas Texas, Wilkes-Barre Pennsylvania, Arizona, Denver Colorado, California, Florida, and Sofia Bulgaria starting as low as $7.45 a month. We Be HostiN (https://webehostin.com)
Tags: back, backup, copy, create, file, gunzip, gzip, image, img, lvm, remote, restore, server, up, update, volume
