|
|
对openstack而言,虚拟机的快照即是镜像,快照做完后以镜像形式存于glance。虽然openstack的快照是基于libvirt(qemu-kvm),但是二者在实现上有很大区别:8 c4 O. o. D4 N+ L6 F: Y7 G
libvirt 主流快照实现: 采用virDomainSnapshotCreateXML()函数(CLI为virsh snapshot-create)。 新建的快照与虚拟机有关联:若为内置快照,快照信息和虚拟机存在同一个qcow2镜像中;若为外置快照,新建一个qcow2文件,原虚拟机的disk将变为一个read only的模板镜像,新qcow2镜像仅记录与2.模板镜像的差异数据。这种快照包含快照链信息,可保留disk和ram信息,可回滚至快照点。
# B6 O. ?- C9 I# N, R5 Gopenstack快照实现:openstack并未采用virDomainSnapshotCreateXML()来实现快照,而是单纯的对虚拟机镜像做转换和拷贝,生成一个与虚拟机无关联的镜像,最后上传至glance中。这种快照不包含快照链信息,只保留disk信息,无法回滚至快照点,只能采用该快照镜像创建一个新的虚拟机。
2 a; T& t" z3 H
/ t! E0 O; ~; h2. cold snapshot and live snapshot0 ~, h: f0 ?) Q9 s3 k- C' V
cold snapshot: 创建snapshot时,需暂停虚拟机。
# Y8 [- T" `# h' \ Klive snapshot: 创建snapshot时,无需暂停虚拟机。
5 {- a% I* A0 `0 ~5 N
% Z8 R7 G0 O G. [3. cold snapshot 流程:
/ V. I j( ?; t+ I; D. i# Save the state and stop a running guest, then detach pci devices
3 K' ] g# J3 v* |& U $ virsh managedsave vm* U' ~+ N+ t, P% U X
# Create a qemu internal snapshot7 q" `" R& P9 B7 [# r
$ qemu-img snapshot -c snap1 vm_snapshot& i$ p" ^8 r% I Y, a
# Extract the internal snapshot, convert it to qcow2 and export it a file, then upload to glance" N0 \# q3 K1 B( T* \* P9 b
$ qemu-img convert -f qcow2 vm -O qcow2 vm_snapshot
" ~3 e! X4 [+ X t! ^3 ^* t# Start the guest again( A& h% V1 d( R! m0 N0 O z5 `
$ virsh start vm M8 J7 U2 v: _ M/ Q4 e9 K3 U: y
- X) ?$ ?4 z5 f7 O5 F
4. live snapshot 流程
1 J% e" S" e7 R- p1 O- t# Abort any failed/finished block operations:
. {5 I7 X# e8 e/ v/ r" l $ virsh blockjob vm vda --abort- y0 C- b' g+ C: A- Y8 z
# Undefine a running domain. (Note: Undefining a running domain does not _kill_ the domain, it just converts it from persistent to transient.)3 `# b R3 I; e% w5 Z: \
$ virsh undefine vm
- n% t( m) {& k/ V1 q# create a destination image with the original backing file and matching size of the instance root disk.4 g3 T0 ^' V. O# j$ V I
$ qemu-img create -f qcow2 vm_copy --backing_file=backing_file --size=root_disk_size
, Z# Q0 P7 u, k! `) t) G#Invoke 'virsh blockcopy' (This will take time, depending on the size of disk image vm1):
& z- G% f. p* r8 E' c: x9 U $ virsh blockcopy --domain vm vda vm_copy --wait --verbose' T) b& D/ X2 z; c: ~
#Abort any failed/finished block operations:% I M2 s! i! Q2 [% d3 e3 @2 R$ p
$ virsh blockjob vm vda --abort, b5 D5 h0 r3 G e
#Define the guest again (to make it persistent):0 @& r' Z+ b. V, w% ~3 P
$ virsh define vm
$ L# M: W0 {2 U9 V3 D4 c8 J2 ]#From the obtained new copy, convert the QCOW2 with a backing file to a qcow2 image with no backing file, then upload to glance:% S+ Z6 `9 Z$ N6 ?8 h$ _8 s
$ qemu-img convert -f qcow2 -O raw vm_copy vm_convert
; ^% _+ g9 y) m/ b' h; `% \% S3 E) j. R% z0 x5 J
5. virsh snapshot-create-as/snapshot-create 快照简析 9 `2 p0 w! V2 w& V9 l/ f" }/ {
默认为内置快照,支持快照链,支持快照回滚,支持内存信息。. Z5 H' T- |1 q# s* N$ P
快照过程中,虚拟机短暂卡顿。 |
|