- 积分
- 16843
在线时间 小时
最后登录1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?开始注册
x
对openstack而言,虚拟机的快照即是镜像,快照做完后以镜像形式存于glance。虽然openstack的快照是基于libvirt(qemu-kvm),但是二者在实现上有很大区别:7 N# ~; x A/ T# d0 e
libvirt 主流快照实现: 采用virDomainSnapshotCreateXML()函数(CLI为virsh snapshot-create)。 新建的快照与虚拟机有关联:若为内置快照,快照信息和虚拟机存在同一个qcow2镜像中;若为外置快照,新建一个qcow2文件,原虚拟机的disk将变为一个read only的模板镜像,新qcow2镜像仅记录与2.模板镜像的差异数据。这种快照包含快照链信息,可保留disk和ram信息,可回滚至快照点。& Q% _0 X1 d9 j! ^( B) W
openstack快照实现:openstack并未采用virDomainSnapshotCreateXML()来实现快照,而是单纯的对虚拟机镜像做转换和拷贝,生成一个与虚拟机无关联的镜像,最后上传至glance中。这种快照不包含快照链信息,只保留disk信息,无法回滚至快照点,只能采用该快照镜像创建一个新的虚拟机。
" V. z% K2 N3 g9 Q- O2 V/ O! |4 q2 S; f3 m9 W! z
2. cold snapshot and live snapshot1 {7 N/ I6 ^3 T3 H1 F/ y
cold snapshot: 创建snapshot时,需暂停虚拟机。# v) S. G0 ~% k, d# f/ [. `: t/ d( ~: j
live snapshot: 创建snapshot时,无需暂停虚拟机。* G7 A# R) D) J
- J7 W$ @+ V- \. o# M# ^3. cold snapshot 流程:
$ E6 U8 a, j: S7 U; \# Save the state and stop a running guest, then detach pci devices6 o7 @) {, u% N8 h7 n
$ virsh managedsave vm! F# j4 p1 D7 b7 B* J
# Create a qemu internal snapshot
: \/ c5 Y3 W* e8 N $ qemu-img snapshot -c snap1 vm_snapshot/ i: n- ]) E' `- v
# Extract the internal snapshot, convert it to qcow2 and export it a file, then upload to glance
2 }) ^: R. ~0 {$ z $ qemu-img convert -f qcow2 vm -O qcow2 vm_snapshot- X J; O0 e+ o" v
# Start the guest again
- y. J- N7 T! d& N3 r $ virsh start vm
2 T1 u) Y! i2 q0 O k/ a ) D7 `: Z, v# @ j
4. live snapshot 流程
5 x9 Z! ?5 a3 B8 x- K/ |# Abort any failed/finished block operations:1 @( Y5 J7 ]; L: p
$ virsh blockjob vm vda --abort
& ]( [9 G: u/ Y# d# Undefine a running domain. (Note: Undefining a running domain does not _kill_ the domain, it just converts it from persistent to transient.)
9 w: n4 t, n G k" k% v& V2 L% r $ virsh undefine vm' X$ x' t. d ?1 I
# create a destination image with the original backing file and matching size of the instance root disk.
$ g7 m: D3 T" {* v/ u $ qemu-img create -f qcow2 vm_copy --backing_file=backing_file --size=root_disk_size6 N. `" m/ z: l# ]; h
#Invoke 'virsh blockcopy' (This will take time, depending on the size of disk image vm1):1 T ?/ v+ _, W8 s4 j3 q+ ~% h0 b: u& Z
$ virsh blockcopy --domain vm vda vm_copy --wait --verbose
3 k9 U2 P6 L0 O3 ^- G#Abort any failed/finished block operations:
1 J6 q! W. |/ J! \5 [0 l! ]# x $ virsh blockjob vm vda --abort
9 _: K6 v. ?. M c9 j) i8 R2 l7 n. A4 _#Define the guest again (to make it persistent):# D7 Z4 J x$ f5 R: ^( A
$ virsh define vm
% R7 ^$ ?# @) y, L% a* o! L# w#From the obtained new copy, convert the QCOW2 with a backing file to a qcow2 image with no backing file, then upload to glance:) O2 X- x$ Y% `8 Y @- E$ W
$ qemu-img convert -f qcow2 -O raw vm_copy vm_convert, d2 r$ d1 s4 d6 n9 v
" `% y( t4 `8 |6 D# x
5. virsh snapshot-create-as/snapshot-create 快照简析 0 G8 H( l4 x* Q0 T- U
默认为内置快照,支持快照链,支持快照回滚,支持内存信息。
2 O: K3 i7 R' E) ], A 快照过程中,虚拟机短暂卡顿。 |
|