{"id":9,"date":"2014-09-20T15:50:11","date_gmt":"2014-09-20T13:50:11","guid":{"rendered":"http:\/\/www.underealm.com\/tech\/?p=9"},"modified":"2014-09-23T18:38:06","modified_gmt":"2014-09-23T16:38:06","slug":"mass-xenserver-updates-with-batch-script","status":"publish","type":"post","link":"https:\/\/www.underealm.com\/tech\/2014\/09\/mass-xenserver-updates-with-batch-script\/","title":{"rendered":"Mass XenServer updates with batch script"},"content":{"rendered":"<p>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 <a title=\"XenServer bash script\" href=\"http:\/\/virtexperience.com\/2013\/06\/24\/fastest-way-to-patch-xenserver-using-a-script\/\">this article<\/a>, that I modified slightly for my lesser needs and built it around a Win7 XenCenter installation.<\/p>\n<pre class=\"toolbar:2\" lang=\"batch\"><code>@echo off\r\nset XE=\"C:\\Program Files (x86)\\Citrix\\XenCenter\\xe.exe\"\r\nset Patch=<\\\\FILESERVER\\PathToUpdates\\|DRIVE:\\LocalPathToUpdates\\>\r\nset Server=-s <SERVER_IP> -u <SERVER_USER> -pw <SERVER_PASSWORD>\r\nset HostID=<UUID_OF_XENSERVER_HOST>\r\n\r\nif not \"%1\"==\"\" goto :Patch\r\n\r\ndel \"%Patch%*.bz2\" >nul 2>&1\r\nfor %%f in (\"%Patch%*.zip\") do %XE% %Server% patch-upload file-name=\"%Patch%%%~nf.xsupdate\"\r\necho -- Run the command again passing the IDs as parameters\r\ngoto :End\r\n\r\n:Patch\r\necho -- Now installing: %1\r\n%XE% %Server% patch-apply host-uuid=%HostID% uuid=%1\r\nshift\r\nif not \"%1\"==\"\" goto :Patch\r\n\r\n:End<\/code><\/pre>\n<p>The first four parameters are shortcuts to the <strong>xe.exe<\/strong>, the <strong>path to the patches location<\/strong>, the <strong>remote server data<\/strong> and finally the <strong>UUID of the XS host<\/strong>. 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.<\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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=&#8221;C:\\Program Files (x86)\\Citrix\\XenCenter\\xe.exe&#8221; set [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[6,5,7,58,59],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-xenserver","tag-batch-script","tag-citrix","tag-scripts","tag-sysad","tag-xenserver"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts\/9"}],"collection":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":0,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.underealm.com\/tech\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}