This is what my setup looks like: ubuntu 14.04 running KVM with libvirt has a HW-Raid it's running from (/dev/sda) and another HW-RAID (/dev/sdb) that is the PV to a LVM VG called "datavg" with virtual machines installed into unformatted LVs. Then I backed up the VM like so:
- save libvirt/virsh config
- save the lv size
- save first 512Bytes (MBR & GPT) using dd
- create a LVM snapshot of the LV
- map the partitions (using kpartx) and mount the root partition of the vm
- save fs type and uuid of that partition
- use duplicity to do incremental backup of everything (exclude /proc)
- unmount & unmap
- remove snapshot
This is what i ran on the "way back" to restore it to a vm called "test-vm" in a LV "vm-test-lv":
create LV with the same size (from backup)
lvcreate --name vm-test-lv --size 400.00G datavg
dd the MBR & GPT back into the first 512b at the beginning of the LV
dd if=/data/backup/test/MBR-20141126T104236Z.raw of=/dev/datavg/vm-test-lv
map the LV partitions
kpartx -av /dev/datavg/vm-test-lv
format it in the same FS with the same UUID (both from backup)
mkfs.ext4 -U a5943cc4-6421-47a4-9613-30efd4dc44d4 /dev/mapper/datavg-vm--test--lv1
mount the freshly formatted partition
mount /dev/mapper/datavg-vm--test--lv1 /data/mnt/
restore the duplicity backup
duplicity restore --progress --restore-time 20141126T104236Z file:///data/backup/test /data/mnt
unmount it
umount /data/mnt
remove the mapping
kpartx -d /dev/mapper/datavg-vm--test--lv
create the virtual machine (in this case with a different name and uuid because the original one still exists but is powered off)
virsh create /data/backup/test/virsh-20141126T104236Z.xml
try to boot
That didn't work and it's hanging, looking at it through VNC via a SSH tunnel it's saying "Booting from Hard Disk..." (screenshot since i'm not allowed to post inline images)
I then tried to map it again, and chroot into it to try and do grub-install
but that didn't work either:
root@kvm-host:~# mkdir /data/mnt/proc
root@kvm-host:~# mount --bind /proc /data/mnt/proc
root@kvm-host:~# mount --bind /dev /data/mnt/dev
root@kvm-host:~# mount --bind /sys /data/mnt/sys
root@kvm-host:~# chroot /data/mnt
root@kvm-host:/# grub-install /dev/mapper/datavg-vm--test--lv
Installing for i386-pc platform.
grub-install: error: disk `lvmid/eLefkO-MKtH-kOcq-pt0b-4zzO-31xg-XIqDpY/AcNuFk-JY2r-V8x5-gNoV-UCoi-uQug-8R0ZWZ' not found.
It is showing the correct UUIDs of the VG and the LV but i fear i'm using it wrong... Can anyone help me out?