由于VM是可能存在于不同节点上,所以当一个计算节点挂掉后,可以把挂掉的节点运行的VM在新的节点上继续运行。
虽然快照功能可以做恢复使用,但是毕竟快照只能恢复固定时间的VM,所以虚拟机备份很重要!对做好热备份有很大的帮助!
注:以测试集群为例,把c01上的vm1备份到c02上面
步骤:
1.首先,查看待备份vm1的信息:
在目录“/var/lib/nova/instances/$VM_ID/”下面有如下文件:
console.log disk libvirt.xml
其中,disk里面没有包含数据,只是一个包含vm基本信息的文件。
2.在“/var/lib/nova/instances/$VM_ID/”目录下输入如下信息: kvm-img info disk
3.在/var/lib/nova/instances/下新建目录backup_vm1,把上述信息备份到c02下的一个目录/var/lib/nova/instances/backup_vm1下面。
4.用disk生成新的磁盘文件newdisk:qemu-img convert disk –O qcow2 newdisk
5.在c02上新建和vm1同配置的虚拟机vm2,保持vm2关闭状态。
6.进入到c02上的/etc/libvirt/qemu/,编辑执行对应得编号:virsh edit $instance-Number
(使用virsh edit,直接用使用vi后,在define会覆盖修改内容)
7.把file和path的路径都改成备份文件backup_vm1中文件的路径。
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file= '/var/lib/nova/instances/backup_vm1/newdisk' />
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<interface type='bridge'>
<mac address='fa:16:3e:f9:55:56'/>
<source bridge='br-int'/>
<virtualport type='openvswitch'>
<parameters interfaceid='e5198be1-22ce-46b6-ba83-3f9f7d6b928d'/>
</virtualport>
<target dev='tape5198be1-22'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='file'>
<source path=' /var/lib/nova/instances/backup_vm1/console.log '/>
<target port='0'/>
</serial>
<serial type='pty'>
<target port='1'/>
</serial>
<console type='file'>
<source path='/var/lib/nova/instances/backup_vm1/console.log'/>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0' keymap='en-us'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<driver name='qemu' type='qcow2' cache='none'/>
<source file= '/var/lib/nova/instances/backup_vm1/newdisk' />
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<interface type='bridge'>
<mac address='fa:16:3e:f9:55:56'/>
<source bridge='br-int'/>
<virtualport type='openvswitch'>
<parameters interfaceid='e5198be1-22ce-46b6-ba83-3f9f7d6b928d'/>
</virtualport>
<target dev='tape5198be1-22'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='file'>
<source path=' /var/lib/nova/instances/backup_vm1/console.log '/>
<target port='0'/>
</serial>
<serial type='pty'>
<target port='1'/>
</serial>
<console type='file'>
<source path='/var/lib/nova/instances/backup_vm1/console.log'/>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0' keymap='en-us'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
8.启动vm2即可!