- 积分
- 16843
在线时间 小时
最后登录1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?开始注册
x
对openstack而言,虚拟机的快照即是镜像,快照做完后以镜像形式存于glance。虽然openstack的快照是基于libvirt(qemu-kvm),但是二者在实现上有很大区别:
$ |# m ~' ^! ]$ d1 U% P4 Blibvirt 主流快照实现: 采用virDomainSnapshotCreateXML()函数(CLI为virsh snapshot-create)。 新建的快照与虚拟机有关联:若为内置快照,快照信息和虚拟机存在同一个qcow2镜像中;若为外置快照,新建一个qcow2文件,原虚拟机的disk将变为一个read only的模板镜像,新qcow2镜像仅记录与2.模板镜像的差异数据。这种快照包含快照链信息,可保留disk和ram信息,可回滚至快照点。6 I. {% {9 F1 A4 l3 B. R2 u* a
openstack快照实现:openstack并未采用virDomainSnapshotCreateXML()来实现快照,而是单纯的对虚拟机镜像做转换和拷贝,生成一个与虚拟机无关联的镜像,最后上传至glance中。这种快照不包含快照链信息,只保留disk信息,无法回滚至快照点,只能采用该快照镜像创建一个新的虚拟机。! e2 x+ W* L e
0 J0 o# x [( K4 }2. cold snapshot and live snapshot
" s6 s3 i- [5 X$ A7 S: jcold snapshot: 创建snapshot时,需暂停虚拟机。
) Q4 G2 m, B8 p/ \6 F) D! Flive snapshot: 创建snapshot时,无需暂停虚拟机。* L& x+ n0 c8 G5 v9 A0 L, c
8 V. A/ i+ g( a; J; C' w
3. cold snapshot 流程:
: R& x. s1 D2 t1 F# e( v/ w$ a# Save the state and stop a running guest, then detach pci devices
, Z9 M! f- G- ]0 p9 G3 g $ virsh managedsave vm
6 ^3 g: C2 K' B8 z9 y! a# Create a qemu internal snapshot
) J: t4 i! ?+ k2 E4 A5 c: E $ qemu-img snapshot -c snap1 vm_snapshot5 d" F l+ Y7 U# S
# Extract the internal snapshot, convert it to qcow2 and export it a file, then upload to glance
' L4 b5 J; \, H, L6 R $ qemu-img convert -f qcow2 vm -O qcow2 vm_snapshot
& A p" u" Q9 Q: U1 v# Start the guest again) C; A, M/ H% ~, c% d
$ virsh start vm4 V+ l v2 W+ I X# A
3 d# |/ `+ f: h! l1 R% N8 L6 M; b
4. live snapshot 流程) u# \- W( d0 `6 j0 @
# Abort any failed/finished block operations:! ~5 c) K8 A9 L& U2 \
$ virsh blockjob vm vda --abort
$ i; h1 M9 Y; y8 d1 X( p* Z# Undefine a running domain. (Note: Undefining a running domain does not _kill_ the domain, it just converts it from persistent to transient.)% b& T8 Z; E1 q) c
$ virsh undefine vm$ m( r. [0 `) |( i
# create a destination image with the original backing file and matching size of the instance root disk.
: V5 B( l& Z3 W: A% _0 f $ qemu-img create -f qcow2 vm_copy --backing_file=backing_file --size=root_disk_size
6 l6 e$ K$ u/ t' j& C f#Invoke 'virsh blockcopy' (This will take time, depending on the size of disk image vm1):
1 F' {2 O3 O& t $ virsh blockcopy --domain vm vda vm_copy --wait --verbose, O5 j. o; v8 S' n) W
#Abort any failed/finished block operations:9 U) F. Z* o$ \- I# k! P
$ virsh blockjob vm vda --abort
& n; Q2 \' r. }1 Q#Define the guest again (to make it persistent):
2 o# {$ ] w0 l* X% f+ P $ virsh define vm
, B: P3 D* K0 G. V3 `0 b#From the obtained new copy, convert the QCOW2 with a backing file to a qcow2 image with no backing file, then upload to glance:1 `9 `: W) w9 s/ C' r% u9 c
$ qemu-img convert -f qcow2 -O raw vm_copy vm_convert' o0 N+ S6 A( U! z4 M
. I2 \# `4 V' x% ?6 O* S. ]% I5. virsh snapshot-create-as/snapshot-create 快照简析
! O$ @6 S0 B+ M; ]0 e 默认为内置快照,支持快照链,支持快照回滚,支持内存信息。$ J% ]8 r3 {: ?/ a0 x+ W
快照过程中,虚拟机短暂卡顿。 |
|