Roland Giesler
2013-Oct-02 15:56 UTC
[libvirt-users] Snapshots: Where they are stored and how to use them?
Firstly I'd like to learn where a snapshot is stored once it has been made. I understand that the principle is that when changes occur in the VM, the difference is written to the snapshot, thus recording the differences between the date/time of the snapshot and the current value of the VM. Is that a correct assessment of the process? If that is indeed so, can I take regular snapshots and back then up onto external storage to provide a sort of system restore point at certain times in the past? I have scanned the server hard disks for the snapshot images after running "sudo virsh snapshot-create Windows /etc/libvirt/snapshot.xml" and the system reports a snapshot was taken, yet I cannot find any file that contains the snapshot. $ sudo virsh snapshot-list Windows Name Creation Time State ------------------------------------------------------------ Windows 2013-10-02 12:41:06 +0200 running What will happen to the snapshot if the host server is restarted? Some insight would be greatly appreciated. regards Roland
Eric Blake
2013-Oct-02 17:27 UTC
Re: [libvirt-users] Snapshots: Where they are stored and how to use them?
On 10/02/2013 09:56 AM, Roland Giesler wrote:> Firstly I'd like to learn where a snapshot is stored once it has been > made.That depends - did you create an external or an internal snapshot? 'virsh snapshot-info Windows Windows' will help.> I understand that the principle is that when changes occur in > the VM, the difference is written to the snapshot, thus recording the > differences between the date/time of the snapshot and the current > value of the VM. Is that a correct assessment of the process?Sort of. The differences aren't recorded in the snapshot, so much as it records the contents at the point in time it was taken, and running the VM now tracks the differences compared to when the snapshot was taken. That is, the snapshot is not being modified, but the current state.> > If that is indeed so, can I take regular snapshots and back then up > onto external storage to provide a sort of system restore point at > certain times in the past?Yes, that is one use for snapshots (done better with external snapshots, because qemu 1.6 lacks the ability to let you view the contents of internal snapshots while the domain is running - patches have been proposed for qemu 1.7 to start addressing that, but then libvirt would also have to be taught to take advantage of the new qemu feature). But be aware that external snapshots are still not fully implemented in libvirt - while you can create them, we do not yet have decent support in place for libvirt-only revert or delete of a snapshot. See this wiki page for more than you ever wanted to know about management of external snapshots (and update it, if you'd like): http://wiki.libvirt.org/page/I_created_an_external_snapshot%2C_but_libvirt_won%27t_let_me_delete_or_revert_to_it> > I have scanned the server hard disks for the snapshot images after > running "sudo virsh snapshot-create Windows /etc/libvirt/snapshot.xml" > and the system reports a snapshot was taken, yet I cannot find any > file that contains the snapshot. > > $ sudo virsh snapshot-list Windows > Name Creation Time State > ------------------------------------------------------------ > Windows 2013-10-02 12:41:06 +0200 runningThen you probably took an internal snapshot, which means that the very qcow2 file that is hosting the disk image is also holding the snapshot. 'qemu-img info /path/to/qcow2' would confirm this.> > What will happen to the snapshot if the host server is restarted?It will still be there, ready for you if you ever want to revert to it. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Kashyap Chamarthy
2013-Oct-02 18:19 UTC
Re: [libvirt-users] Snapshots: Where they are stored and how to use them?
On 10/02/2013 09:26 PM, Roland Giesler wrote:> Firstly I'd like to learn where a snapshot is stored once it has been > made.If you've created external snapshots, then all the files should be under /var/lib/libvirt/images/ Here's just a quick test I did on my laptop: Before snapshot: =============== # List the current block device of your guest $ virsh domblklist f19oz Target Source ---------------------------------------------- vda /var/lib/libvirt/images/f19oz.dsk Create an external disk-only snapshot: ===================================== Note, the guest was running when I did the below: $ virsh snapshot-create-as f19oz snap1 "snap1-desc" --disk-only --atomic Domain snapshot snap1 created After snapshot: ============== # Notice how the current disk image is the new one ending with .snap1 $ virsh domblklist f19oz Target Source ------------------------------------------------ vda /var/lib/libvirt/images/f19oz.snap1 Optionally:View the entire backing chain of your images: $ qemu-img info --backing-chain /var/lib/libvirt/images/f19oz.snap1 image: /var/lib/libvirt/images/f19oz.snap1 file format: qcow2 virtual size: 3.0G (3221225472 bytes) disk size: 196K cluster_size: 65536 backing file: /var/lib/libvirt/images/f19oz.dsk backing file format: raw image: /var/lib/libvirt/images/f19oz.dsk file format: raw virtual size: 3.0G (3221225472 bytes) disk size: 834M> I understand that the principle is that when changes occur in > the VM, the difference is written to the snapshot, thus recording the > differences between the date/time of the snapshot and the current > value of the VM. Is that a correct assessment of the process?True. There are several different flavours of snapshots. These are discussed elsewhere, writing it here for convenience: 1) Internal Snapshots, these can be: 1.1. Internal 'disk snapshot' -- {live/offline} 1.2. Internal 'system checkpoint' snapshot -- {live} With Internal Snapshots, a single qcow2 file holds everything: original & its delta. The original file /must/ be a QCOW2 file. NOTE: 'system checkpoint' meaning -- it captures VM state and disk state. Where VM state indicates: it captures memory and device state (but not "disk" state). 2) External Snapshots, these can be: 2.1. External 'disk snapshot' -- {live/offline}. i.e: snapshot of the disk is saved in one file, and the delta since the snapshot is tracked in a new qcow2 file. 2.2. External 'system checkpoint' -- {live}. i.e: the guest's disk-state will be saved in one file, its RAM & device-state will be saved in another new file.> > If that is indeed so, can I take regular snapshots and back then up > onto external storage to provide a sort of system restore point at > certain times in the past?I don't know what you mean by "regular snapshots" here. However, an example of live backup using libvirt's blockcopy -- http://kashyapc.fedorapeople.org/virt/lc-2012/live-backup-with-blockcopy.txt> > I have scanned the server hard disks for the snapshot images after > running "sudo virsh snapshot-create Windows /etc/libvirt/snapshot.xml"I think you created an 'internal' snapshot (defined above) here. Meaning, your Original and the delta are stored in the single file. So you'll not find snapshot images files lying around. Examining the content of your /etc/libvirt/snapshot.xml would be more useful.> and the system reports a snapshot was taken, yet I cannot find any > file that contains the snapshot. > > $ sudo virsh snapshot-list Windows > Name Creation Time State > ------------------------------------------------------------ > Windows 2013-10-02 12:41:06 +0200 running > > What will happen to the snapshot if the host server is restarted?The snapshot is still preserved.> > Some insight would be greatly appreciated.PS: This presentation may give you more idea on different snapshots available -- http://kashyapc.fedorapeople.org/virt/lc-2012/lceu-2012-virt-snapshots-kashyap-chamarthy.pdf And, some examples listed here (slightly old, but should still be valid) -- http://kashyapc.fedorapeople.org/virt/lc-2012/snapshots-illustration.txt Hope that helps. -- /kashyap
Possibly Parallel Threads
- Virsh snapshots
- Re: virsh snapshot-create and blockcopy
- Looks like blockpull does not accept a subset of the entire chain of backing files
- Efficient live disk backup with active blockcommit : Failed 'block-commit': Could not reopen file: Permission denied
- virsh snapshot-create and blockcopy