2

I have spent about a week trying to figure out how to backup/restore/restore a virt-manager VM including all snapshots.

If I examine the qcow2 file it contains all the snapshots that were made:

sudo qemu-img snapshot -l '../LinuxLiteV3.8.qcow2'
           
Snapshot list:
ID        TAG                     VM SIZE                DATE       VM CLOCK   
1         LinuxLite38_PreUD01         0 B 2020-11-06 23:37:14   00:00:00.000
2         snapshot1                   0 B 2020-12-27 15:59:03   00:00:00.000

I can take this file to another instance of virt-manager, and recreate the VM and it will run, but virt-manager appears to have no knowledge of the snapshots.

Since the original VM still exists if necessary I could create xml files using:

virsh dumpxml LinuxLiteV3.8 --security-info --migratable >LinuxLiteV3.8
virsh snapshot-dumpxml LinuxLiteV3.8 LinuxLite38_PreUD01 --security-info  >LinuxLite38_PreUD01.xml
virsh snapshot-dumpxml LinuxLiteV3.8 snapshot1 --security-info  >snapshot1.xml

but I have no idea how to import the definitions into virt-manager.

IIUC virsh snapshot-create will create a new snapshot and not import an existing snapshot.

At this time, I am trying to recreate several machines that are defined as qemu:///system that I want to move to qemu:///session. I know virsh has a -c option that allows a choice to be made between qemu:///system and qemu:///session, but I don't know how to export/import.

I also am in the process of migrating my system to new hardware, so I need to be able to reload VMs and their snapshots on a new installation of virt-manager. I am assuming that this is essentially the same problem only I'm exporting on one system and importing on another.

It would be preferable to work with only the qcow2 file, but since I still have the original working install I have the option of working with the xml files.

3
  • Did you try virsh snapshot-create ... Commented Jan 10, 2021 at 20:02
  • IIUC virsh snapshot-create ... creates a new snapshot - essentially the same as clicking the + (add snapshot) on virt-manager which is going to damage the file. If someone knows FOR SURE that I am wrong, please let me know. Commented Jan 10, 2021 at 22:22
  • man virsh says for snapshot-create: If --redefine is specified, then all XML elements produced by snapshot-dumpxml are valid; this can be used to migrate snapshot hierarchy from one machine to another... , or to make slight alterations in the snapshot metadata (such as host-specific aspects of the domain XML embedded in the snapshot). When this flag is supplied, the xmlfile argument is mandatory, and the domain's current snapshot will not be altered unless the --current flag is also given. Commented Jan 11, 2021 at 11:33

1 Answer 1

3

With an older VM named "sled9", having two disks and two snapshots, I did the following:

On the source machine:

~$ virsh dumpxml sled9 > sled9.xml
~$ virsh snapshot-list sled9
   Name        Creation Time               State
   --------------------------------------------------
   snapshot1   2021-01-10 20:58:45 +0100   shutoff
   vor grub    2019-05-03 12:43:30 +0200   running

~$ virsh snapshot-dumpxml sled9 snapshot1 > snapshot1.xml
~$ virsh snapshot-dumpxml sled9 'vor grub' > vor_grub.xml

Copied the two disk files and the three xml files to the target machine, into newly created directory /var/lib/libvirt/images/sled9

On the target machine:

First modified the three xml files to reflect the different path to the disk files (from /var/lib/libvirt/images/local to /var/lib/libvirt/images/sled9). This is only important, if the paths differ on the different machines. Then

  ~$  virsh define sled9.xml 
  ~$  virsh snapshot-create sled9 --xmlfile vor_grub.xml --redefine
  ~$  virsh snapshot-create sled9 --xmlfile snapshot1.xml --redefine
  ~$  virsh snapshot-list sled9
     Name        Creation Time               State
     --------------------------------------------------
     snapshot1   2021-01-10 20:58:45 +0100   shutoff
     vor grub    2019-05-03 12:43:30 +0200   running

The domain was shown in the virtmanager on the target machine, the snapshots were shown, and the VM could be started without problems after modifying the network interface, which is different on both machines.

It is important to redefine the snapshots in the correct order, otherwise virsh will complain (missing parent).

1
  • This is a good answer. You can make changes to the machine configuration provided those changes are consistent throughout all machine and snapshot XML files. Commented Apr 20, 2022 at 1:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.