Categories
XenServer

Mass XenServer updates with batch script

I was looking for a way to optimize (read: not doing repetitive tasks by hand) the patches upload on my XenServer machine. I based it off a script, shown in this article, that I modified slightly for my lesser needs and built it around a Win7 XenCenter installation.

@echo off
set XE="C:\Program Files (x86)\Citrix\XenCenter\xe.exe"
set Patch=<\\FILESERVER\PathToUpdates\|DRIVE:\LocalPathToUpdates\>
set Server=-s  -u  -pw 
set HostID=

if not "%1"=="" goto :Patch

del "%Patch%*.bz2" >nul 2>&1
for %%f in ("%Patch%*.zip") do %XE% %Server% patch-upload file-name="%Patch%%%~nf.xsupdate"
echo -- Run the command again passing the IDs as parameters
goto :End

:Patch
echo -- Now installing: %1
%XE% %Server% patch-apply host-uuid=%HostID% uuid=%1
shift
if not "%1"=="" goto :Patch

:End

The first four parameters are shortcuts to the xe.exe, the path to the patches location, the remote server data and finally the UUID of the XS host. I download the packages in the directory and unzipped its content. When the script is ran without parameters it will remove any sources package I might have mistakenly extracted, it scans the path for any and all ZIP packages and, based on their names, uploads the extracted XSUPDATE to the XenServer host, returning a list of patch UUIDs. After that I can launch the script again passing a parameter list with the returned patch UUIDs, and it will cycle through them all and apply them. After they have been applied correctly I can reboot the XenServer host and delete the ZIP packages.

This is a bit rough around the edges, but it works when you only have a handful machines to upgrade. There is a lot of room for improvement though, and I might get back to it at a later date.

Leave a Reply

Your email address will not be published. Required fields are marked *