User Tools

Site Tools


virtualization:xenserver:xenserver_backup_cli

Creating Backups of Running VMs in XenServer (XCP)

FIXME Needs testing and updating

Manual Mode

With XenServer it is possible to create backups of VMs, even if they are running. The process is as follows:

  1. Search for the uuid of the VMs to backup
  2. Create a snapshot of each (running) VM
  3. Save the snapshot to file
  4. Remove the created snapshot

First look for the uuid of the VMs to backup. We don’t want to backup the control domain itself, so we add is-control-domain=false to the vm-list command and we also don’t want backups of snapshots so we add is-a-snapshot=false:

xe vm-list is-control-domain=false is-a-snapshot=false

Now we create a snapshot of the VMs we want to backup, replacing the uuid one by one with the ones we found with the previous command. Also replace the name of the snapshot if desired:

xe vm-snapshot uuid=<uuid of VM> new-name-label=<snapshotname>

:!: Note the return value (the uuid of the created snapshot).

Then we transform the snapshot into a VM to be able to export it to a file. Replace the uuid with the return value of the previous command:

xe template-param-set is-a-template=false ha-always-run=false uuid=<uuid of snapshot>

In the next step we export the snapshot to a file. Replace the uuid with the snapshot uuid and provide a meaningful filename:

xe vm-export vm=<uuid of snapshot> filename=/path/to/filename.xva

In the final step we delete the snapshot:

xe vm-uninstall uuid=<uuid of snapshot> force=true

Scripted Mode

#!/bin/bash

datum=`date +%Y%b%d`
xsname=`hostname`
uuidfile=/root/xenuuids.txt
mountpoint=/var/removable
backuppath=$mountpoint/vms/$xsname/$datum

if [ ! -d $mountpoint/vms ]; then
 mount /dev/sdb1 $mountpoint
 mkdir $mountpoint/vms
fi

if [ ! -d $mountpoint/vms ]; then
 echo "No mountpoint found. Please check!"
 exit 0
fi

mkdir -p $backuppath
if [ ! -d $backuppath ]; then
 echo "No backup path found. Please check!"
 exit 0
fi

xe vm-list is-control-domain=false is-a-snapshot=false | grep uuid | cut -d":" -f2 > $uuidfile

if [ ! -f $uuidfile ]; then
 echo "No UUID file found. Please check!"
 exit 0
fi

while read VMUUID
 do
  VMNAME=`xe vm-list uuid=$VMUUID | grep name-label | cut -d":" -f2 | sed 's/^ *//g'`
  SNAPUUID=`xe vm-snapshot uuid=$VMUUID new-name-label="SNAPSHOT-$VMNAME-$datum"` 

  xe template-param-set is-a-template=false ha-always-run=false uuid=$SNAPUUID
  xe vm-export vm=$SNAPUUID filename=$backuppath/SNAPSHOT-$VMNAME-$datum.xva
  xe vm-uninstall uuid=$SNAPUUID force=true

done <$uuidfile

umount $mountpoint

exit
virtualization/xenserver/xenserver_backup_cli.txt · Last modified: 2023/05/15 12:28 by gcooper