This article describes how to back up metadata for an individual Virtual Machines on Citrix Xen Servers. In this article, you will get step by step instructions for backing up metadata. Also at end of this article, there is a small shell script which can be used for backup metadata for all VMs running on the Xen server.
1. Backup VMs Metadata in Citrix Xenserver
1.1. Find VMs UUID
Use the following command to get list of UUIDs of all vms along with other details. this UUID will be used in next steps.
xe vm-list is-control-domain= false is-a-snapshot=false
uuid ( RO) : 8ac95696-94f3-83c1-bc89-8bb2603f832b name-label ( RW): test-vm power-state ( RO): running
As per above output test-vm uuid is “8ac95696-94f3-83c1-bc89-8bb2603f832b“.
1.2. Backup Metadata using UUID
After getting UUID of vm, use following command to backup metadata of virtual machine with uuid 8ac95696-94f3-83c1-bc89-8bb2603f832b and create metadata backup file metadata.bak.
xe vm-export filename= metadata.bak uuid=8ac95696-94f3-83c1-bc89-8bb2603f832b metadata=true
You have completed vm metadata backup successfully.
2. Script for Backup All VMs Metadata
This is a good option to schedule metadata backup regularly. You can schedule the below script for backup all the vms metadata on Xen server.
How to use script:
2.1 – Copy this script to a file /scripts/metadata-backup.sh in xenserver.
2.2 – This script is using a remote backup server mounted using nfs, You can replace this with your own settings.
2.3 – Execute this script using sh /scripts/metadata-backup.sh.
2.4 – For regular backup schedule this in systems crontab. [Crontab Examples]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #!/bin/bash DATE=$(date +%d%B%y) XSNAME=`echo $HOSTNAME` mkdir -p /mnt/nfs mount -F nfs 192.168.10.100:/backup/citrix/metadata /mnt/nfs BACKUPPATH=/mnt/nfs/$XSNAME/$DATE mkdir -p $BACKUPPATH xe vm-list is-control-domain=false is-a-snapshot=false | grep uuid | cut -d":" -f2 > /tmp/uuids.txt while read line do VMNAME=`xe vm-list uuid=$line | grep name-label | cut -d":" -f2 | sed 's/^ *//g'` xe vm-export filename="$BACKUPPATH/$XSNAME-$VMNAME-$DATE" uuid=$line metadata=true done < /tmp/uuids.txt umount /mnt/nfs |