From July 2015

Very bad hammond style boxes

Unfortunately I managed to pick up some real stinkers. They weren’t even that cheap – about £4.50 each, I got 4, the first one I used was alright, took quite a bit of sanding. The other 3, 2 are mostly unusable, one is probably fine with a bit of sanding.

Stick to what you know folks! I am going to just use Eddystone boxes I think now, or the 125b’s from Tayda for things a bit bigger.

in the interest of naming and shaming – it’s this seller here and this is the actual item. I have contacted seller but heard nothing back from him.

Xenserver Pool Backup Script

There is a couple of good scripts about on the internet for backing up running Xenserver servers, but I don’t think they are that elegant – they rely on temp files, there is no logging, and there is no folder maintenance. I’ve written this one script that can be run on one member of a pool (best to run it on the master) and it will backup all the virtual machines in the pool, their metadata, the pool database and the hosts. It also provides logging, clears it’s logs, and clears old backups. It also doesn’t create temp files and uses variables where others have used temp files. I’m not a developer, so this is maybe still a bit hacky, but it works great for me!

There is absolutely no support for this script, use it at your own risk – works perfectly for me but please test in your environment before you start using it in production.

#!/bin/bash

# Written By: Matt Artley
# Created date: 22/06/2015
# Version: 2
# Visit: http://www.mattartley.com

# Define all variables

DATE=$(date +%y-%m-%d)
MOUNT="1.2.3.4:/mount/point/"
MOUNTTYPE="-t nfs"
MOUNTPOINT="/mnt/vmbackup"
BACKUPPATH=$MOUNTPOINT/VMHOSTS/$DATE
LOGPATH=/var/log/vmbackup
LOGFILE=$LOGPATH/vmb-$DATE
UUIDS="$(xe vm-list is-control-domain=false is-a-snapshot=false params=uuid --minimal | tr ',' '\n')"
VMHOSTNAMES=( Host1 Host2 Host3 Host4 Host5 )
MASTER="Host1"

# Check for LOGPATH and create if needed

if [ ! -d "$LOGPATH" ]; then
	echo "Creating Log Directory"
	mkdir -p $LOGPATH
else
	echo "Log Directory exists - moving on"
fi

exec 3>&1 1>>${LOGFILE} 2>&1

# Check for MOUNTPOINT and create if neccessary 

echo "Check Mountpoint"

if [ ! -d "$MOUNTPOINT" ]; then
	echo "Creating MOUNTPOINT Directory"
	mkdir -p $MOUNTPOINT
else
	echo "MOUNTPOINT Directory exists - moving on"
fi

echo "Check Mountpoint....OK"
	
# Mounting remote NFS share backup NAS

echo "Connect to Remote File System (NFS)"

if grep -qs "$MOUNT" /proc/mounts; then
	echo "File system already Mounted"
else
	echo "File system is not mounted, preparing to mount"
	mount $MOUNTTYPE $MOUNT $MOUNTPOINT 
		if [ $? -eq 0 ]; then
			echo "Mount success!"
		else
			echo "Something went wrong with the mount...oops"
			exit
		fi
fi

echo "Connect to Remote File System (NFS)....OK"

# Create Backup Directory

echo "Create Backup Directory on Remote Storage"

mkdir -p $BACKUPPATH

echo "Create Backup Directory on Remote Storage....OK"

# VMHost backups

if [ ! -d "$BACKUPPATH/VMHOSTS" ]; then
	echo "Creating VMHOSTS Directory"
	mkdir -p $BACKUPPATH/VMHOSTS
else
	echo "VMHOSTS Directory exists - moving on"
fi

for POOLMEMBER in ${VMHOSTNAMES[@]}
do
	echo "Starting host-backup $POOLMEMBER"
	xe host-backup file-name=$BACKUPPATH/VMHOSTS/$POOLMEMBER-$DATE.bak host=$POOLMEMBER
	if [ $? -eq 0 ]; then
		echo "host-backup $POOLMEMBER....OK"
	else
		echo "host-backup $POOLMEMBER....Failed"
	fi
done

# Pool database dump (only to be run on Master)

if [ "$HOSTNAME" = "$MASTER" ]; then
	echo "Server is MASTER - Starting pool-dump-database"
	xe pool-dump-database file-name=$BACKUPPATH/VMHOSTS/pool-DB-$DATE.bak
	if [ $? -eq 0 ]; then
		echo "pool-dump-database....OK"
	else
		echo "pool-dump-database....Failed"
	fi
fi

# Actual export and backup of VMs happens here

for VMUUID in $UUIDS
do 
	VMNAME=`xe vm-list uuid=$VMUUID | grep name-label | cut -d":" -f2 | sed 's/^ *//g'`
	echo "Now moving to $VMNAME"
	SNAPUUID=`xe vm-snapshot uuid=$VMUUID new-name-label="SNAPSHOT-$VMUUID-$DATE"`
	echo "Creating Snapshot of $VMNAME"
	xe template-param-set is-a-template=false ha-always-run=false uuid=$SNAPUUID
	if [ $? -eq 0 ]; then
	echo "Creating Snapshot of $VMNAME....OK"
	else
	echo "Creating Snapshot of $VMNAME....Failed"
	fi
	echo "Exporting .XVA of $VMNAME"
	xe vm-export vm=$SNAPUUID filename="$BACKUPPATH/$VMNAME-$DATE.xva"
	if [ $? -eq 0 ]; then
	echo "Exporting .XVA of $VMNAME....OK"
	else
	echo "Exporting .XVA of $VMNAME....Failed"
	fi
	echo "Export vm metadata"
	xe vm-export uuid=$VMUUID filename="$BACKUPPATH/$VMNAME-$DATE" metadata=true
	if [ $? -eq 0 ]; then
	echo "Export vm metadata....OK"
	else
	echo "Export vm metadata....Failed"
	fi
	echo "Removing created snapshot of $VMNAME"
	xe vm-uninstall uuid=$SNAPUUID force=true
	if [ $? -eq 0 ]; then
	echo "Removing created snapshot of $VMNAME....OK"
	else
	echo "Removing created snapshot of $VMNAME....Failed"
	fi
	
done


# Clear old vm backups 

find $MOUNTPOINT/VMHOSTS/* -mtime +2 -exec rm -rf {} \;

# unmount file system

umount $MOUNTPOINT
if [ $? -eq 0 ]; then
	echo "Filesystem unmounted"
else
	echo "Problem unmounting the filesystem"
fi

# Clear Log Directory of logs older than 3 weeks

find $LOGPATH/ -mtime +21 -exec rm {} \;