User Tools

Site Tools


libvirt:libvirt

This is an old revision of the document!


Libvirt

Copy a VM

Export

In this example a running VM named 'foobar' is exported:

cd /my/backup/dir/foobar
virsh dumpxml foobar > foobar.xml

In order to copy the virtual harddrive the VM probably needs to be shut down. Otherwise the running state will need a memory dump as well and we don't want that now. So; shut down the VM and run the following command:

# Find location of image:
virsh dumpxml foobar | grep '\.img'

cd /my/backup/dir/foobar
cp /location/of/image/foobar.img .

Import

Now we can import it again. First copy the harddrive image to the correct location and make sure to modify the xml accoringly (if it was moved). Optionally change the name if so desired by modifying the contents of the <name> tag in line 2. Now import the VM:

cd /my/backup/dir/foobar
virsh define foobar.xml

Backup a running VM

Store

cd /my/backup/dir/foobar

# Pause the VM
virsh suspend foobar

# Dump the VM configuration
virsh dumpxml foobar > foobar.xml

# Copy the virtual harddrive
# Find location of image:
virsh dumpxml foobar | grep '\.img'
cp /location/of/image/foobar.img .

# Dump the state (memory, network etc...)
virsh save foobar foobar.state

Restore

cd /my/backup/dir/foobar

# Copy the virtual harddrive
virsh dumpxml foobar | grep '\.img'
cp /location/of/image/foobar.img .

# Recreate VM configuration from file:
virsh define foobar.xml

# Restore the state (memory, network etc...)
virsh restore foobar.state

# Resume the VM
virsh resume
libvirt/libvirt.1407396972.txt.gz · Last modified: 2014/08/07 09:36 by deva