|
|
对openstack而言,虚拟机的快照即是镜像,快照做完后以镜像形式存于glance。虽然openstack的快照是基于libvirt(qemu-kvm),但是二者在实现上有很大区别:" c. R$ N* w- o% |" o' Y0 R
libvirt 主流快照实现: 采用virDomainSnapshotCreateXML()函数(CLI为virsh snapshot-create)。 新建的快照与虚拟机有关联:若为内置快照,快照信息和虚拟机存在同一个qcow2镜像中;若为外置快照,新建一个qcow2文件,原虚拟机的disk将变为一个read only的模板镜像,新qcow2镜像仅记录与2.模板镜像的差异数据。这种快照包含快照链信息,可保留disk和ram信息,可回滚至快照点。
9 D& r7 S8 C3 s Fopenstack快照实现:openstack并未采用virDomainSnapshotCreateXML()来实现快照,而是单纯的对虚拟机镜像做转换和拷贝,生成一个与虚拟机无关联的镜像,最后上传至glance中。这种快照不包含快照链信息,只保留disk信息,无法回滚至快照点,只能采用该快照镜像创建一个新的虚拟机。
, D* s3 {- D& q3 @( n: F/ H r
$ ~ S0 f+ _, B6 x- N2 Y$ M2. cold snapshot and live snapshot1 w& b% ?3 x( D- J8 P/ w
cold snapshot: 创建snapshot时,需暂停虚拟机。
! E4 j' q: B# y% ]live snapshot: 创建snapshot时,无需暂停虚拟机。2 U/ @- @- K, s: l* {8 q( f
( i$ d0 n+ Q/ E( {/ ^) W3. cold snapshot 流程:
( }8 {( s4 E+ y* j" g# Save the state and stop a running guest, then detach pci devices' J+ L" T4 ~7 t6 h
$ virsh managedsave vm
B1 B) T* d! s! B9 T# X, K% r# Create a qemu internal snapshot( v. Y' i' X: f& D: b
$ qemu-img snapshot -c snap1 vm_snapshot" b# F. a* X% r" W
# Extract the internal snapshot, convert it to qcow2 and export it a file, then upload to glance
A7 E( M) Z5 P1 e& I $ qemu-img convert -f qcow2 vm -O qcow2 vm_snapshot
' H, {6 J; T0 |# Start the guest again
5 m' O! `- p5 f+ y8 u4 G $ virsh start vm
+ c0 r3 e G L
/ u i3 l. P4 N* q4. live snapshot 流程
2 l% e v" h* t+ h1 P; x" H# Abort any failed/finished block operations:$ q! J- G4 l6 c
$ virsh blockjob vm vda --abort
& w, Z6 ?/ h8 b( ^" c# Undefine a running domain. (Note: Undefining a running domain does not _kill_ the domain, it just converts it from persistent to transient.)
! \3 V% u: t5 e9 V4 o2 W $ virsh undefine vm
* s/ m0 O5 X% ^* Z. }# create a destination image with the original backing file and matching size of the instance root disk.
% v3 s) P, r* V# o* x5 e3 A $ qemu-img create -f qcow2 vm_copy --backing_file=backing_file --size=root_disk_size8 U4 f- ?+ @" }" o( {& f- t
#Invoke 'virsh blockcopy' (This will take time, depending on the size of disk image vm1):6 t) W3 a a& ^: J" E. r0 p
$ virsh blockcopy --domain vm vda vm_copy --wait --verbose
2 @) v# e1 A$ B/ q4 s- Z* V#Abort any failed/finished block operations:
6 D2 c) Z; ^( d6 L |( k( I $ virsh blockjob vm vda --abort
& H* Y: h* b# a' F( N1 G#Define the guest again (to make it persistent):
8 g& o$ a$ g! z J- [' d, F5 A $ virsh define vm& F( X! z; ~' }* L
#From the obtained new copy, convert the QCOW2 with a backing file to a qcow2 image with no backing file, then upload to glance:/ j/ l% ^5 ~/ v
$ qemu-img convert -f qcow2 -O raw vm_copy vm_convert
" N2 Y3 @& U, f( g% }" ^! T# e) @8 G
5. virsh snapshot-create-as/snapshot-create 快照简析
0 u! ]- _5 k4 B$ q$ C9 ?% h 默认为内置快照,支持快照链,支持快照回滚,支持内存信息。: @ v* C4 S7 L' ^" M( r. P# ~0 Y1 v
快照过程中,虚拟机短暂卡顿。 |
|