KVM Virtualization Storage Volume Removal, Off-Line Archival and Restoration
Internal
Overview
This procedures can be used to remove a storage volume from a storage pool, while archiving its content off-line, and then restore the storage volume and its content at a later date.
Storage Volume Removal and Content Archival
1. Read the storage pool statistics before removal:
virsh pool-info <storage-pool-name>
Name: main-storage-pool UUID: 5e3b81b6-a596-404f-a091-ef738dc21df5 State: running Persistent: yes Autostart: yes Capacity: 874.04 GiB Allocation: 568.73 GiB Available: 305.31 GiB
The allocation and availability values will modify after procedure. For cross-reference, the 'df' information for the block device the storage pool resides on could also be recorded:
df -h ... /dev/sda7 875G 620G 255G 71% /main-storage-pool
2. Read capacity and allocation of the volume(s) to be archived:
virsh vol-list --details <pool-name> ... node3-docker.raw /main-storage-pool/node3-docker.raw file 10.00 GiB 10.00 GiB node3.qcow2 /main-storage-pool/node3.qcow2 file 10.00 GiB 3.34 GiB ...
3. Determine the storage pool mapping on the virtualization host filesystem:
virsh pool-dumpxml <storage-pool-name>
<pool type='fs'> <name>main-storage-pool</name> ... <target> <path>/main-storage-pool</path> ...
4. Identify the file(s) corresponding to the storage volume(s) we want to archive.
virsh vol-list <storage-pool-name>
Name Path ------------------------------------------------------------------------------ ... node3-docker.raw /main-storage-pool/node3-docker.raw node3.qcow2 /main-storage-pool/node3.qcow2 ...
5. "Download" the volume content into file. Use the name of the volume, with a ".download" postfix:
virsh vol-download /main-storage-pool/node3.qcow2 ./node3.qcow2.download virsh vol-download /main-storage-pool/node3-docker.raw ./node3-docker.raw.download
6. Optionally, gzip the content:
cat node3-docker.raw.download | gzip > node3-docker.raw.download.gz
7. Export volume definition:
virsh vol-dumpxml /main-storage-pool/node3.qcow2 > node3.qcow2.xml virsh vol-dumpxml /main-storage-pool/node3-docker.raw > node3-docker.raw.xml
8. Archive volume definition and content.
9. Remove the volumes from the pool:
virsh vol-delete node3-docker.raw --pool main-storage-pool virsh vol-delete node3.qcow2 --pool main-storage-pool
Storage Volume Restoration
1. Create the empty storage volumes based on their previously saved XML definition:
virsh vol-create <pool-name> ./volume-definition-file.xml
The pool name is found inside the volume definition file.
2. Expand and upload the previously saved storage volume content:
gunzip node3.qcow2.download.gz virsh vol-upload <volume-name> <content-file> --pool <storage-pool-name> --offset 0 virsh vol-upload node3.qcow2 ./node3.qcow2.download --pool main-storage-pool --offset 0
3. Check consistency:
qemu-img check /main-storage-pool/node3.qcow2