20.7. Managing a Virtual Machine Configuration
20.7.1. Saving a Guest Virtual Machine's Configuration
virsh save [--bypass-cache] domain file [--xml string] [--running] [--paused] [--verbose]command stops the specified domain, saving the current state of the guest virtual machine's system memory to a specified file. This may take a considerable amount of time, depending on the amount of memory in use by the guest virtual machine. You can restore the state of the guest virtual machine with the
virsh restore(Section 20.6.4, “Restoring a Guest Virtual Machine”) command.
virsh savecommand and the
virsh suspendcommand, is that the
virsh suspendstops the domain CPUs, but leaves the domain's
qemuprocess running and its memory image resident in the host system. This memory image will be lost if the host system is rebooted.
virsh savecommand stores the state of the domain on the hard disk of the host system and terminates the
qemuprocess. This enables restarting the domain from the saved state.
virsh savewith the
virsh domjobinfocommand and cancel it with the
virsh savecommand can take the following arguments:
--bypass-cache- causes the restore to avoid the file system cache but note that using this flag may slow down the restore operation.
--xml- this argument must be used with an XML file name. Although this argument is usually omitted, it can be used to supply an alternative XML file for use on a restored guest virtual machine with changes only in the host-specific portions of the domain XML. For example, it can be used to account for the file naming differences in underlying storage due to disk snapshots taken after the guest was saved.
--running- overrides the state recorded in the save image to start the guest virtual machine as running.
--paused- overrides the state recorded in the save image to start the guest virtual machine as paused.
--verbose- displays the progress of the save.
Example 20.8. How to save a guest virtual machine running configuration
virsh save guest1 guest1-config.xml --running
20.7.2. Defining a Guest Virtual Machine with an XML File
virsh define filenamecommand defines a guest virtual machine from an XML file. The guest virtual machine definition in this case is registered but not started. If the guest virtual machine is already running, the changes the changes will take effect once the domain is shut down and started again.
Example 20.9. How to create a guest virtual machine from an XML file
virsh define guest1-config.xml
20.7.3. Updating the XML File That will be Used for Restoring a Guest Virtual Machine
virsh save-image-define filename [--xml /path/to/file] [--running] [--paused]command updates the guest virtual machine's XML file that will be used when the virtual machine is restored used during the
virsh restorecommand. The --xml argument must be an XML file name containing the alternative XML elements for the guest virtual machine's XML. For example, it can be used to account for the file naming differences resulting from creating disk snapshots of underlying storage after the guest was saved. The save image records if the guest virtual machine should be restored to a running or paused state. Using the arguments
--pauseddictates the state that is to be used.
Example 20.10. How to save the guest virtual machine's running configuration
virsh save-image-define guest1-config.xml
20.7.4. Extracting the Guest Virtual Machine XML File
virsh save-image-dumpxml filecommand will extract the guest virtual machine XML file that was in effect at the time the saved state file (used in the
virsh savecommand) was referenced. Using the
--security-infoargument includes security sensitive information in the file.
Example 20.11. How to pull the XML configuration from the last save
virsh save-image-dumpxml guest1-config.xml
20.7.5. Editing the Guest Virtual Machine Configuration
virsh save-image-edit <file>command edits the XML configuration file that was created by the
virsh savecommand. See Section 20.7.1, “Saving a Guest Virtual Machine's Configuration” for information on the
--pausedstate. Without using these arguments in the
save-image-editcommand, the state is determined by the image file itself. By selecting
--running(to select the running state) or
--paused(to select the paused state) you can overwrite the state that
virsh restoreshould use.
Example 20.12. How to edit a guest virtual machine's configuration and restore the machine to running state
virsh save-image-edit guest1-config.xml