To Duplicate/Backup a Xen VM in a Logical Volume

技术笔记. 请忽略 🙂

0, If you are to duplicate, create VMs on destination server, just to create conf files and logical volumes for VMs and hold the place for source VMs.

#xen-create-image –hostname [HOSTNAME] –ip [IP] –vcpus 2 –pygrub –dist squeeze

1, Create an LVM snapshot for the VM’s logical volume.

#lvcreate -L[SIZE] -s -n [SNAPSHOTNAME] /dev/[VOLUMEGROUP]/[LOGICALVOLUME]

2, Shutdown the VM if optional. Login the VM and shut down or:

#xm shutdown [VM]

3, Copy the snapshot over to destination server. Login to the source server and do

#dd bs=4M if=/dev/[VOLUMEGROUP]/[SNAPSHOTNAME] | gzip -1 – | ssh [USER]@[DESTINATION] dd bs=4M of=[/PATH]/tmp.gz

3.1, If step 3 is successful, you can remove the snapshot optionally.

#lvremove /dev/[VOLUMEGROUP]/[SNAPSHOTNAME]

4, Restore the volume image to the target logical volume on destination server. Better make the target volume bigger than the source volume.

#dd bs=4M if=[/PATH]/tmp.gz | gunzip -1 – | dd bs=4M of=/dev/[TARGETVOLUMEGROUP]/[TARGETLOGICALVOLUME]

4.1, If the target volume is bigger than the source volume(which is recommended), check and resize:

#e2fsck -f /dev/[TARGETVOLUMEGROUP]/[TARGETLOGICALVOLUME]
#resize2fs /dev/[TARGETVOLUMEGROUP]/[TARGETLOGICALVOLUME]

5, Mount target volume for modifications such as IP, etc. And un-mount after this.

#mount /dev/[TARGETVOLUMEGROUP]/[TARGETLOGICALVOLUME] /[MOUNTPATH]
#umount /dev/[TARGETVOLUMEGROUP]/[TARGETLOGICALVOLUME]

6, Compare both source and destination VM configuration files if there’s different booting methods.

7, Boot up the cloned VMs and test.

#xm create [HOSTNAME].cfg
#xm top

🙂

2 Replies to “To Duplicate/Backup a Xen VM in a Logical Volume”

  1. VM = Virtual Machine. VM是在一台电脑上同时运行多个系统, 并且相互隔绝, 这样能更好的利用硬件资源, 也更方便转移或者备份.

Leave a Reply

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