Server: XenServer 7.1

Management: XenCenter

Goal: Have a Scheduled Snapshot saved to an external drive connected to the server via USB

Issue: The server recognizes the external drive as a removable storage repository but I'm unable to find where to set it as a default location for snapshots.

  • Does scheduling a copy via cron and the host itself would be a better solution ? – yagmoth555 Oct 11 at 12:46
  • 1
    Yeah, came up with a similar idea. I'll answer the question on my own tomorrow with the script I've wrote. It is still bugging a bit, but almost working. BRB – Bert Oct 11 at 15:16

So here is the code I've created. This runs every day at 4am via the cron of the SUDO

#!/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

Enjoy! :)

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.