15

I am trying to live-snapshot using KVM as per this procedure.

I must have messed up at some point because I'm in a state I don't understand.

My VM is called prod. It was created in file /srv/vm/prod.qcow2.

Apparently, there is no running snapshot: I'm working on the base file. I can guess because the modification date of file /srv/vm/prod.qcow2 changes every minute or so. Besides, this command confirms it:

# virsh domblklist prod
Target     Source
------------------------------------------------
vda        /srv/vm/prod.qcow2

And there is nothing to blockcommit:

# virsh blockcommit prod vda --active --pivot
error: invalid argument: top '/srv/vm/prod.qcow2' in chain for 'vda' has no backing file

However, libvirt keeps trace of an old snapshot:

# virsh snapshot-list prod
 Name                 Creation Time             State
------------------------------------------------------------
 snap                 2015-06-09 12:11:33 +0200 disk-snapshot

Its descriptor file is /var/lib/libvirt/qemu/snapshot/prod/snap.xml:

<domainsnapshot>
  <name>snap</name>
  <state>disk-snapshot</state>
  <creationTime>1433844693</creationTime>
  <memory snapshot='no'/>
  <disks>
    <disk name='vda' snapshot='external' type='file'>
      <driver type='qcow2'/>
      <source file='/srv/vm/snap.qcow2'/>
    </disk>
  </disks>
[...]

The source file /srv/vm/snap.qcow2 was deleted.

Considering the method I'm trying to implement, it is pretty likely that this snapshot was created with the following command:

virsh snapshot-create-as --domain prod snap --diskspec vda,file=/srv/vm/snap.qcow2 --disk-only --atomic

I can't remove it:

# virsh snapshot-delete prod snap
error: Failed to delete snapshot snap
error: unsupported configuration: deletion of 1 external disk snapshots not supported yet

So I am in a state where a snapshot was created, is apparently no longer used, and can't be deleted.

Is there something I can do about it?

Should I care or can I just ignore it?

Edit

I just removed the snapshot file descriptor.

# systemctl stop libvirt
# mv /var/lib/libvirt/qemu/snapshot/prod/snap.xml /home/jerome
# systemctl start libvirt

My VM is up again and I don't see any reference to the snapshot anymore.

# virsh snapshot-list prod
 Name                 Creation Time             State
------------------------------------------------------------

Nothing in virt-manager either.

Am I fine or is there still some housekeeping to do?

Edit 2

Apparently, passing -–no-metadata to virsh snapshot-create-as would avoid this issue by not creating the .xml file, thus keeping no trace of the snapshot.

Jérôme
  • 565
  • 1
  • 5
  • 18
  • 1
    After you delete the snapshot file descriptor, there should be still some evidence of an existing snapshot left in the VM image itself which can be checked with `qemu-img info /srv/vm/prod.qcow2`. But I am not sure how to remove that trace myself... – sdittmar Jan 30 '20 at 17:19
  • @sdittmar you may want to contact the libvirt-users mailing-list (see my answer) to get a precise answer to this. – Jérôme Jan 31 '20 at 09:26

1 Answers1

24

The proper method was

virsh snapshot-delete prod --metadata snap

(This command can be found on the wiki. I tried it before asking here but it failed due to a typo that has been corrected since.)

I don't know what it does that is not covered by removing the .xml file while libvirtd is down. Maybe the only difference is that stopping libvirtd is not needed. Even so, maybe this could evolve in the future. In any case, it is recommended to use libvirt's API rather than playing with files directly.

This call is indeed not needed if the snapshot was created with the --no-metadata argument.

I obtained this clarification in this thread of the libvirt-users mailing-list.

Anyone willing to do backups via live snapshots should read aforementioned wiki page, and may be interested in the forum thread which answers my noob questions, and points to slides from Eric Blake, as well as this blog post and following comments.

Jérôme
  • 565
  • 1
  • 5
  • 18
  • 2
    Awesome thread dude... Thanks for sharing, saved me headaches ;) – Orsiris de Jong Jul 14 '20 at 10:26
  • If, like me, you got here while trying to make backups of your running VMs, please note there now is a way easier method: `virsh backup-begin vm1`. Read about it on https://libvirt.org/kbase/live_full_disk_backup.html. – Onnonymous Jun 17 '22 at 09:24