1

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.

Bert
  • 984
  • 1
  • 11
  • 29
  • Does scheduling a copy via cron and the host itself would be a better solution ? – yagmoth555 Oct 11 '18 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 '18 at 15:16

1 Answers1

1

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! :)

Bert
  • 984
  • 1
  • 11
  • 29