http://kashyapc.com/2011/10/04/snapshotting-with-libvirt-for-qcow2-images/
Snapshotting with libvirt for qcow2 images
Libvirt 0.9.6 was recently out. Take a look at 0.9.5 changelog for truckload of features/bugfixes/cleanups(specifically snapshot related) from the libvirt team.
Libvirt 0.9.6가 최근 나왔습니다. libvirt 팀으로부터 나온 기능/버그픽스/클린업(특히 스냅샷과 관련된)의 truckload를 위한 0.9.5 changelog를 한 번 보십시오.
So, I grabbed the F14 srpm from Libvirt ftp, and made a quick Fedora koji scratch build of libvirt-0.9.6 for Fedora 15 and gave the snapshot features a whirl. Here it goes:
그래서, Libvirt ftp로부터 Fedora 14 srpm을 입수하고, Fedora 15를 위한 libvirt-0.9.6의 빠른 Fedora koji 스크래치 빌드를 만들고 스냅샷 기능을 여러 차례 시험하였습니다. 여기에 그것을 기록합니다:
(Also noted below is some very useful discussion I had(on #virt, OFTC) with Eric Blake (Upstream/Red Hat’s Libvirt dev, very friendly guy.) on snapshots. It was way informative not to capture it.)
또한 아래의 기록사항은 스냅샷에 관한 나와 Eric Blake(업스트림/레드햇 Libvirt 개발, 아주 친한 녀석)와의 매우 유용한 토론(#virt, OFTC) 내용입니다.
Context on types of snapshots
At the moment, snapshotting in KVM/QEMU/Libvirt land is supported primarily for QCOW2 disk images. I briefly discussed about Qcow2 previously here.
순간, KVM/QEMU/Libvirt 스냅샷은 1차적으로 QCOW2 디스크 이미지를 위해 지원되었습니다. 나는 Qcow2에 대해 여기서 이전에 간단히 토론하였습니다.
There are several different types of snapshots possible. Some idea on that:
몇 가지 가능한 스냅샷 종류가 있습니다. 몇몇 의견입니다.
Internal snapshot: A type of snapshot, where a single QCOW2 file will hold both the ‘saved state’ and the ‘delta’ since that saved point. ‘Internal snapshots’ are very handy because it’s only a single file where all the snapshot info is captured, and easy to copy/move around the machines.
Internal snapshot : 단일 QCOW2 파일이 저장 포인트 시점부터 'saved state'와 ‘delta'를 함께 행하는 스냅샷의 한 종류. 'Internal snapshots'은 모든 스냅샷 정보가 캡쳐되어 있는 오직 하나의 단일 파일이고 머신 범위 안에서 copy/move가 쉽기 때문에 매우 편리합니다.
External snapshot: Here, the ‘original qcow2 file’ will be in a ‘read-only’ saved state, and the new qcow2 file(which will be generated once snapshot is created) will be the *delta* for the changes. So, all the changes will now be written to this delta file. ‘External Snapshots’ are useful for performing backups. Also, external snapshot creates a qcow2 file with the original file as its backing image, and the backing file can be /read/ in parallel with the running qemu.
External snapshot: 여기에, 'original qcow2 파일'은 'read-only'로 저장된 상태가 될 것이고, 새로운 qcow2 파일(스냅샷이 생성되자마자 generate될)은 변경을 위해 *delta*가 될 것입니다. 그래서, 모든 변경은 이제 이 delta 파일에 쓰일 것입니다. 'External Snapshot'은 백업 실행에 유용합니다. 또한, external snapshot은 그것의 백업 이미지로서 원본 파일과 함께 qcow2 파일을 생성하고, 백업 파일은 qemu 실행과 병행하여 /read/가 될 수 있습니다.
VM State: This will save the guest/domain state to a file. So, if you take a snapshot including VM state, we can then shut off that guest and use the freed up memory for other purposes on the host or for other guests. Internally this calls qemu monitor’s ‘savevm’ command. Note that this only takes care of VM state(and not disk snapshot). To try this out:
VM State: 이것은 guest/domain 상태를 파일로 저장할 것입니다. 그러므로, 당신이 VM state를 포함하는 스냅샷을 얻는다면, 우리는 guest를 shut off할 수 있고 host 내 다른 목적 또는 다른 guest를 위해 메모리 여유 공간을 확보할 수 있습니다. 내부적으로 이것은 qemu 모니터의 'savevm' 명령을 호출합니다. 이것이 오직 VM state(그리고 디스크 스냅샷이 아닌)를 보호한다는 점을 기록하십시오. 이를 이끌어낼 시도를 위해서는:
# Memory before saving the guest f15vm3
##############################################
[root@moon ~]# free -m
total used free shared buffers cached
Mem: 10024 5722 4301 0 164 4445
-/+ buffers/cache: 1112 8911
Swap: 0 0 0
##############################################
[root@moon ~]# virsh list
Id Name State
----------------------------------
5 f15guest running
6 f15vm3 running
##############################################
# Save the guest f15vm3 to a file 'foof15vm3'
[root@moon ~]# virsh save f15vm3 foof15vm3
Domain f15vm3 saved to foof15vm3
##############################################
# Now, f15vm3 is gracefully saved/shutdown.
[root@moon ~]# virsh list
Id Name State
----------------------------------
5 f15guest running
##############################################
# Notice the RAM being freed
[root@moon ~]# free -m
total used free shared buffers cached
Mem: 10024 5418 4605 0 164 4493
-/+ buffers/cache: 760 9263
Swap: 0 0 0
##############################################
# Let's restore the guest back from the file 'foof15vm3'
[root@moon ~]# virsh restore foof15vm3
Domain restored from foof15vm3
##############################################
# list the status. f15vm3 is up and running.
[root@moon ~]# virsh list
Id Name State
----------------------------------
5 f15guest running
7 f15vm3 running
##############################################
##############################################
[root@moon ~]# free -m
total used free shared buffers cached
Mem: 10024 5722 4301 0 164 4445
-/+ buffers/cache: 1112 8911
Swap: 0 0 0
##############################################
[root@moon ~]# virsh list
Id Name State
----------------------------------
5 f15guest running
6 f15vm3 running
##############################################
# Save the guest f15vm3 to a file 'foof15vm3'
[root@moon ~]# virsh save f15vm3 foof15vm3
Domain f15vm3 saved to foof15vm3
##############################################
# Now, f15vm3 is gracefully saved/shutdown.
[root@moon ~]# virsh list
Id Name State
----------------------------------
5 f15guest running
##############################################
# Notice the RAM being freed
[root@moon ~]# free -m
total used free shared buffers cached
Mem: 10024 5418 4605 0 164 4493
-/+ buffers/cache: 760 9263
Swap: 0 0 0
##############################################
# Let's restore the guest back from the file 'foof15vm3'
[root@moon ~]# virsh restore foof15vm3
Domain restored from foof15vm3
##############################################
# list the status. f15vm3 is up and running.
[root@moon ~]# virsh list
Id Name State
----------------------------------
5 f15guest running
7 f15vm3 running
##############################################
For brevity, let’s try out internal disk snapshots where all the snapshot info (like disk and VM state info) are stored in a single qcow2 file.
신속성을 위해, 모든 스냅샷 정보가 단일 qcow2 파일에 저장되는 곳인 internal disk snapshot을 시도합시다.
Virsh(libvirt shell interface to manage guests) has some neat options for snapshot supports. So, I’ve got an F15 guest (Qcow2 disk image).
Virsh(guest 관리를 위한 libvirt shell interface)는 스냅샷 지원을 위한 몇몇 적절한 옵션을 갖고 있습니다. 그래서, 나는 Fedora 15 guest를 준비하였습니다(Qcow2 디스크 이미지)
Internal Disk Snapshots when the guest is online/running
For illustration purpose, let's use a Fedora-15 guest called 'f15guest'.
[root@moon ~]# virsh list
Id Name State
----------------------------------
4 f15guest running
[root@moon ~]#
Id Name State
----------------------------------
4 f15guest running
[root@moon ~]#
For clarity, ensure there are no prior snapshot instances around.
명료성을 위해, 이전의 스냅샷 인스턴스가 없도록 하십시오.
[root@moon ~]# virsh snapshot-list f15guest
Name Creation Time State
------------------------------------------------------------
[root@moon ~]#
Name Creation Time State
------------------------------------------------------------
[root@moon ~]#
Before creating a snapshot, we need to create a snapshot xml file with 2 simple elements (name and description) if you need sensible name for the snapshot. Note that only these two fields are user settable. Rest of the info. will be filled by Libvirt.
스냅샷 생성 전에, 만약 당신이 스냅샷 식별 용도의 이름을 필요로 한다면 우리는 2개의 단순 요소(이름과 설명)와 함께 스냅샷 xml 파일을 생성할 필요가 있습니다. 나머지 정보는 Libvirt에 의해 채워집니다.
[root@moon ~]# cat /var/tmp/snap1-f15guest.xml
<domainsnapshot>
<name>snap1-f15pki </name>
<description>F15 system with dogtag pki packages </description>
</domainsnapshot>
[root@moon ~]#
<domainsnapshot>
<name>snap1-f15pki </name>
<description>F15 system with dogtag pki packages </description>
</domainsnapshot>
[root@moon ~]#
Eric Blake noted that, the domainsnapshot xml file is optional now for ‘snapshot-create’ if you don’t need a description for the snapshot. And if it’s okay with libvirt generating the snapshot name for us. (More on this, refer below)
Eric Blake는 스냅샷을 위한 description이 필요하지 않을 시 domainsnapshot xml 파일은 'snapshot-create' 용도로는 현재 선택사항이라 기록하였습니다. 그리고 우리를 위한 스냅샷 이름을 생성하는 것은 libvirt에서는 괜찮습니다.
Now, I’m taking a snapshot while the ‘guest’ is running live. Here, Eric noted that, especially when running/live, the more RAM the guest has, and the more active the guest is modifying that RAM, the longer the it will take to create a snapshot. This was a guest was mostly an idle guest.
지금, 'guest'가 실시간 실행 동안 나는 스냅샷을 얻고 있습니다. 특히 그 guest가 갖는 더 많은 RAM, 그리고 그 guest가 그 RAM을 수정하는 더욱 active한 상태인 running/live 때에, 스냅샷을 생성하는 데에 더 오래 걸린다고 여기에 Eric은 기록하였습니다. 이것은 guest가 대부분 idle guest인 경우였습니다.
[root@moon ~]# virsh snapshot-create f15guest /var/tmp/snap1-f15guest.xml
Domain snapshot snap1-f15pki created from '/var/tmp/snap1-f15guest.xml'
[root@moon ~]#
Domain snapshot snap1-f15pki created from '/var/tmp/snap1-f15guest.xml'
[root@moon ~]#
While the snapshot-creation is in _progress_ on the live guest, the state of the guest will be ‘paused.
snapshot-creation이 live guest 상에서 _progress_ 상태에 있는 동안, guest의 상태는 'paused'가 될 것입니다.
[root@moon ~]# virsh list
Id Name State
----------------------------------
4 f15guest paused
[root@moon ~]#
Id Name State
----------------------------------
4 f15guest paused
[root@moon ~]#
Once, the snapshot is created, list the snapshots of f15guest
일단, 스냅샷이 생성되면, f15guest의 스냅샷을 목록에 추가합니다.
[root@moon ~]# virsh snapshot-list f15guest
Name Creation Time State
------------------------------------------------------------
snap1-f15pki 2011-10-04 19:04:00 +0530 running
[root@moon ~]#
Name Creation Time State
------------------------------------------------------------
snap1-f15pki 2011-10-04 19:04:00 +0530 running
[root@moon ~]#
Internal snapshot while the guest is offline
guest 오프라인 동안의 Internal snapshot
For fun, I created another snapshot, but _after_ shutting down the guest. Now, the snapshot creation is just instantaneous.
흥미를 위해, 나는 다른 스냅샷을 생성하였으나, _after_는 guest를 셧다운하고 있었습니다. 지금, 스냅샷 생성은 순간적으로 일어납니다.
[root@moon ~]# virsh list
Id Name State
----------------------------------
[root@moon ~]#
[root@moon ~]# virsh snapshot-create f15guest
Domain snapshot 1317757628 created
[root@moon ~]#
Id Name State
----------------------------------
[root@moon ~]#
[root@moon ~]# virsh snapshot-create f15guest
Domain snapshot 1317757628 created
[root@moon ~]#
List the snapshots of 'f15guest' using virsh.
virsh를 사용하여 'f15guest' 스냅샷을 목록에 나열하시오.
[root@moon ~]# virsh snapshot-list f15guest
Name Creation Time State
------------------------------------------------------------
1317757628 2011-10-05 01:17:08 +0530 shutoff
snap1-f15pki 2011-10-04 19:04:00 +0530 running
Name Creation Time State
------------------------------------------------------------
1317757628 2011-10-05 01:17:08 +0530 shutoff
snap1-f15pki 2011-10-04 19:04:00 +0530 running
To see some information about the VM size, snapshot info:
VM 사이즈에 관한 몇몇 정보를 보기 위한, 스냅샷 정보:
[root@moon ~]# qemu-img info /export/vmimgs/f15guest.qcow2
image: /export/vmimgs/f15guest.qcow2
file format: qcow2
virtual size: 8.0G (8589934592 bytes)
disk size: 3.2G
cluster_size: 65536
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 snap1-f15pki 1.7G 2011-10-04 19:04:00 32:06:34.974
2 1317757628 0 2011-10-05 01:17:08 00:00:00.000
[root@moon ~]#
image: /export/vmimgs/f15guest.qcow2
file format: qcow2
virtual size: 8.0G (8589934592 bytes)
disk size: 3.2G
cluster_size: 65536
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 snap1-f15pki 1.7G 2011-10-04 19:04:00 32:06:34.974
2 1317757628 0 2011-10-05 01:17:08 00:00:00.000
[root@moon ~]#
To revert to a particular snapshot, virsh snapshot-revert domain snapshotname
특별한 스냅샷으로 복귀하기 위한, virsh snapshot-revert domain snapshotname
Also, discussed with Eric, in what cases does virsh invoke Qemu's 'savevm' and 'qemu-img snapshot -c' commands while creating different types of snapshots discussed earlier above. Here is the outline:
또한, 위에서 일찍이 토론했던 다른 종류의 스냅샷을 생성하는 동안 virsh가 Qemu의 'savevm'와 'qemu-img snapshot -c' 명령어를 호출하는 케이스에서 Eric과의 토론이 있었습니다. 여기에 그 개요가 있습니다:
- it uses 'qemu-img snapshot -c' if the domain is offline and –disk-only was not specified
- domain이 offline이고 –disk-only를 지정하지 않았을 시 'qemu-img snapshot -c'를 사용합니다.
- it uses qemu's 'savevm' if the domain is online and –disk-only was not specified
- domain이 online이고 –disk-only를 지정하지 않았을 시 qemu의 'savevm'를 사용합니다.
- it uses qemu's 'snapshot_blkdev' if the domain is online and –disk-only is specified
- domain이 online이고 –disk-only를 지정했을 시 qemu의 'snapshot_blkdev'를 사용합니다.
(Note: –disk-only is an option to capture only ‘disk state’ but not VM state. This option is available w/ virsh ‘snapshot-create’ or ‘snapshot-create-as’ commands.)
(노트: –disk-only는 VM state가 아닌 오직 'disk state'를 캡쳐하기 위한 옵션입니다. 이 옵션은 w/ virsh 'snapshot-create' 또는 'snapshot-create-as' 명령으로 유효합니다.)
Thanks Eric for the detail.
자세한 내용 알려준 Eric에게 감사의 뜻을 전합니다.