Documentation/CreateSnapshot: Difference between revisions

From QEMU
No edit summary
Line 4: Line 4:


  qemu-img create -f qcow2 -b centos-cleaninstall.img snapshot.img
  qemu-img create -f qcow2 -b centos-cleaninstall.img snapshot.img
At this point, you would run QEMU against ''snapshot.img''. Making any changes to its backing file (''centos-cleaninstall.img'') will corrupt this snapshot image.


== Returning to a previous version ==
== Returning to a previous version ==


Since the snapshot is just an image file, if you want to return to the previous version, just delete ''snapshot.img'' and start using the original image again ''centos-55.img''. Please note that if you make any changes to the base image while snapshots remain, those snapshots will become corruptedIf unsure, instead of using the base image directly, just create another snapshot.
A snapshot image cannot be returned to its original state once modified.  Instead delete the first snapshot image (''snapshot.img'' in our example), create another snapshot image of the base image as above, and start using the new .img file.
 
== Modifying the backing file ==
 
Making any changes to a base image (''centos-cleaninstall.img'' in our example) will corrupt its snapshots. Make sure to delete any snapshots before running and modifying the original image.  Use the ''qemu-img info'' command to determine an image's backing file.
 
$ qemu-img info snapshot.img
...
backing file: centos-cleaninstall.img (actual path: centos-cleaninstall.img)
 
== Temporary snapshots ==
 
QEMU also supports temporary snapshots, where the user does not have to explicitly create a separate .img file.  With the ''-snapshot'' flag, any changes made to the virtual machine while it is running are written to temporary files and thrown away when the virtual machine is turned off.  No changes are saved to the original .img file.
 
qemu -hda centos-cleaninstall.img -snapshot

Revision as of 18:33, 28 November 2010

Create a snapshot

Snapshots in QEMU are images that refer to an original image using Copy-on-Write to avoid changing the original image. If you want to create a snapshot of an existing image called centos-cleaninstall.img, create a new QCow2 file using the -b flag to indicate a backing file. The new image is now a read/write snapshot of the original image -- any changes to snapshot.img will not be reflected in centos-cleaninstall.img.

qemu-img create -f qcow2 -b centos-cleaninstall.img snapshot.img

At this point, you would run QEMU against snapshot.img. Making any changes to its backing file (centos-cleaninstall.img) will corrupt this snapshot image.

Returning to a previous version

A snapshot image cannot be returned to its original state once modified. Instead delete the first snapshot image (snapshot.img in our example), create another snapshot image of the base image as above, and start using the new .img file.

Modifying the backing file

Making any changes to a base image (centos-cleaninstall.img in our example) will corrupt its snapshots. Make sure to delete any snapshots before running and modifying the original image. Use the qemu-img info command to determine an image's backing file.

$ qemu-img info snapshot.img
...
backing file: centos-cleaninstall.img (actual path: centos-cleaninstall.img)

Temporary snapshots

QEMU also supports temporary snapshots, where the user does not have to explicitly create a separate .img file. With the -snapshot flag, any changes made to the virtual machine while it is running are written to temporary files and thrown away when the virtual machine is turned off. No changes are saved to the original .img file.

qemu -hda centos-cleaninstall.img -snapshot