|
|
对openstack而言,虚拟机的快照即是镜像,快照做完后以镜像形式存于glance。虽然openstack的快照是基于libvirt(qemu-kvm),但是二者在实现上有很大区别:5 m( F# f6 @! j3 z1 j7 ?4 v
libvirt 主流快照实现: 采用virDomainSnapshotCreateXML()函数(CLI为virsh snapshot-create)。 新建的快照与虚拟机有关联:若为内置快照,快照信息和虚拟机存在同一个qcow2镜像中;若为外置快照,新建一个qcow2文件,原虚拟机的disk将变为一个read only的模板镜像,新qcow2镜像仅记录与2.模板镜像的差异数据。这种快照包含快照链信息,可保留disk和ram信息,可回滚至快照点。
' T8 ?9 C! j' {1 U7 R; T* nopenstack快照实现:openstack并未采用virDomainSnapshotCreateXML()来实现快照,而是单纯的对虚拟机镜像做转换和拷贝,生成一个与虚拟机无关联的镜像,最后上传至glance中。这种快照不包含快照链信息,只保留disk信息,无法回滚至快照点,只能采用该快照镜像创建一个新的虚拟机。
. `% a, a0 Y0 N2 ?+ P
4 x/ x4 q% g7 b; ? ~- E8 ?2. cold snapshot and live snapshot
# H9 D: i6 R# Y2 O* w1 `2 n8 ncold snapshot: 创建snapshot时,需暂停虚拟机。
" `1 m) I& h% n2 D- W/ C9 S4 |live snapshot: 创建snapshot时,无需暂停虚拟机。3 ?# N. L3 t0 `
) B9 R0 h% A# ^, A! q; u3. cold snapshot 流程:
8 L' u- S) t( W3 W- X; v' F# Save the state and stop a running guest, then detach pci devices% R: y- H4 o0 g( i1 U. A1 V9 n
$ virsh managedsave vm
/ F, ~2 W" d3 d1 F' Q, X6 W- F# Create a qemu internal snapshot* F( ?1 P2 e9 ^5 A m7 U
$ qemu-img snapshot -c snap1 vm_snapshot9 f- ]0 u9 N) w4 b: V8 x
# Extract the internal snapshot, convert it to qcow2 and export it a file, then upload to glance
1 u! P# ]4 M0 a$ Z! S0 P0 @* i $ qemu-img convert -f qcow2 vm -O qcow2 vm_snapshot6 K, r3 Q6 M2 _
# Start the guest again+ {4 R% e: n* {$ n: C6 p
$ virsh start vm
" w# f) x6 J; B! }! F# D- s8 O( [6 D
5 o% g6 r2 x7 e5 x1 e" ]" Z4. live snapshot 流程
5 w, a4 c. g( ^! q7 m# Abort any failed/finished block operations:' f6 d: I v2 [2 F0 Q
$ virsh blockjob vm vda --abort
0 Y3 [5 u* A% l6 F# Undefine a running domain. (Note: Undefining a running domain does not _kill_ the domain, it just converts it from persistent to transient.)
4 X! i+ n, e1 O! ~ `, o: o7 X $ virsh undefine vm
, j0 {- l' X/ j2 j n# create a destination image with the original backing file and matching size of the instance root disk., g" P9 i. o L9 D* h b3 ^
$ qemu-img create -f qcow2 vm_copy --backing_file=backing_file --size=root_disk_size/ @ _7 T+ `6 j" {2 L8 ~# s- e
#Invoke 'virsh blockcopy' (This will take time, depending on the size of disk image vm1):3 H" a3 d; |. d N( L2 O' _
$ virsh blockcopy --domain vm vda vm_copy --wait --verbose) c" F+ n; M/ a# D" E
#Abort any failed/finished block operations:
) U# M+ Y; m- n% X8 S/ b' ~ $ virsh blockjob vm vda --abort; R& o+ j6 e% f0 s& l
#Define the guest again (to make it persistent):
6 _( f' g# i' Y' f $ virsh define vm
+ n" k8 ]0 V% b3 h! V9 y#From the obtained new copy, convert the QCOW2 with a backing file to a qcow2 image with no backing file, then upload to glance:
/ z$ l6 D# Q! p $ qemu-img convert -f qcow2 -O raw vm_copy vm_convert' [' T. Z1 Y1 y2 L/ G8 X0 h
8 B# F& W; B0 U; t3 _( z# z5. virsh snapshot-create-as/snapshot-create 快照简析 4 D' _" |3 ?/ n+ y. D; t8 ~' S8 e
默认为内置快照,支持快照链,支持快照回滚,支持内存信息。
' i, Y7 l4 i, d6 i; { 快照过程中,虚拟机短暂卡顿。 |
|