<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Running Systems&#187; vm</title>
	<atom:link href="http://run.tournament.org.il/tag/vm/feed/" rel="self" type="application/rss+xml" />
	<link>http://run.tournament.org.il</link>
	<description>(and me chasing them)</description>
	<lastBuildDate>Wed, 02 Jun 2010 13:50:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>XenServer create snapshots for all machines</title>
		<link>http://run.tournament.org.il/xenserver-create-snapshots-for-all-machines/</link>
		<comments>http://run.tournament.org.il/xenserver-create-snapshots-for-all-machines/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 09:35:03 +0000</pubDate>
		<dc:creator>ez-aton</dc:creator>
				<category><![CDATA[Disk Storage]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting/Programing]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[netapp]]></category>
		<category><![CDATA[shell functions]]></category>
		<category><![CDATA[snapshot]]></category>
		<category><![CDATA[storage]]></category>
		<category><![CDATA[vm]]></category>
		<category><![CDATA[XenServer]]></category>

		<guid isPermaLink="false">http://run.tournament.org.il/?p=483</guid>
		<description><![CDATA[XenServer is a wonderful tool. One of the better parts of it is its powerful scripting language, powered by the &#8216;xe&#8217; command.
In order to capture a mass of snapshots, you can either do it manually from the GUI, or scripted. The script supplied below will include shell functions to capture Quiesce snapshots, and it that [...]


Related posts:<ol><li><a href='http://run.tournament.org.il/quick-provisioning-of-virtual-machines/' rel='bookmark' title='Permanent Link: Quick provisioning of virtual machines'>Quick provisioning of virtual machines</a> <small>When one wants to achieve fast provisioning of virtual machines,...</small></li>
<li><a href='http://run.tournament.org.il/relocating-lvs-with-snapshots/' rel='bookmark' title='Permanent Link: Relocating LVs with snapshots'>Relocating LVs with snapshots</a> <small>Linux LVM is a wonderful thing. It is scalable, flexible,...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>XenServer is a wonderful tool. One of the better parts of it is its powerful scripting language, powered by the &#8216;xe&#8217; command.</p>
<p>In order to capture a mass of snapshots, you can either do it manually from the GUI, or scripted. The script supplied below will include shell functions to capture Quiesce snapshots, and it that fails, normal snapshots of every <strong>running</strong> VM on the system.</p>
<p>Reason: NetApp SnapMirror, or other backup (maybe for later export) scheduled actions.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://run.tournament.org.il/wp-content/plugins/wp-codebox/wp-codebox.php?p=483&amp;download=xen_functions.sh">xen_functions.sh</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4834"><td class="code" id="p483code4"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># This script will supply functions for snapshotting and snapshot destroy including disks</span>
<span style="color: #666666; font-style: italic;"># Written by Ez-Aton</span>
<span style="color: #666666; font-style: italic;"># Visit my web blog for more stuff, at http://run.tournament.org.il</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Global variables:</span>
<span style="color: #007800;">UUID_LIST_FILE</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>SNAP_UUIDS.txt
&nbsp;
<span style="color: #666666; font-style: italic;"># Function</span>
<span style="color: #000000; font-weight: bold;">function</span> assign_all_uuids <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># Construct artificial non-indexed list with name (removing annoying characters) and UUID</span>
	<span style="color: #007800;">LIST</span>=<span style="color: #ff0000;">&quot;&quot;</span>
	<span style="color: #000000; font-weight: bold;">for</span> UUID <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>xe vm-list power-state=running is-control-domain=<span style="color: #c20cb9; font-weight: bold;">false</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> uuid <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #007800;">NAME</span>=<span style="color: #000000; font-weight: bold;">`</span>xe vm-param-get param-name=name-label <span style="color: #007800;">uuid</span>=<span style="color: #007800;">$UUID</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">' '</span> _ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">'('</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">')'</span><span style="color: #000000; font-weight: bold;">`</span>
		<span style="color: #007800;">LIST</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$LIST</span> <span style="color: #007800;">$NAME</span>:<span style="color: #007800;">$UUID</span>&quot;</span>
	<span style="color: #000000; font-weight: bold;">done</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$LIST</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> take_snap_quiesce <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># We attempt to take a snapshot with quench</span>
	<span style="color: #666666; font-style: italic;"># Arguments: $1 name ; $2 uuid</span>
	<span style="color: #666666; font-style: italic;"># We attempt to snapshot the machine and set the value of snap_uuid to the snapshot uuid, if successful.</span>
	<span style="color: #666666; font-style: italic;"># Return 1 if failed</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #007800;">SNAP_UUID</span>=<span style="color: #000000; font-weight: bold;">`</span>xe vm-snapshot-with-quiesce <span style="color: #007800;">vm</span>=<span style="color: #007800;">$2</span> new-name-label=<span style="color: #800000;">${1}</span>_snapshot<span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #666666; font-style: italic;"># echo &quot;Snapshot-with-quiesce for $1 successful&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Snapshot-with-quiesce for $1 failed&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> take_snap <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># We attempt to take a snapshot</span>
	<span style="color: #666666; font-style: italic;"># Arguments: $1 name ; $2 uuid</span>
	<span style="color: #666666; font-style: italic;"># We attempt to snapshot the machine and set the value of snap_uuid to the snapshot uuid, if successful.</span>
	<span style="color: #666666; font-style: italic;"># Return 1 if failed</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #007800;">SNAP_UUID</span>=<span style="color: #000000; font-weight: bold;">`</span>xe vm-snapshot <span style="color: #007800;">vm</span>=<span style="color: #007800;">$2</span> new-name-label=<span style="color: #800000;">${1}</span>_snapshot<span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #666666; font-style: italic;">#echo &quot;Snapshot for $1 successful&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$SNAP_UUID</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Snapshot-with-quiesce for $1 failed&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> stop_ha_template <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># Templates inherit their settings from the origin</span>
	<span style="color: #666666; font-style: italic;"># We need to turn off HA</span>
	<span style="color: #666666; font-style: italic;"># $1 : Template UUID</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Missing template UUID&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	xe template-param-set ha-always-run=<span style="color: #c20cb9; font-weight: bold;">false</span> <span style="color: #007800;">uuid</span>=<span style="color: #007800;">$1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> get_vdi <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># This function will get a space delimited list of VDI UUIDs of a given snapshot/template UUID</span>
	<span style="color: #666666; font-style: italic;"># Arguments: $1 template UUID</span>
	<span style="color: #666666; font-style: italic;"># It will also verify that each VBD is an actual snapshot</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;No arguments? We need the template UUID&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #007800;">VDIS</span>=<span style="color: #ff0000;">&quot;&quot;</span>
	<span style="color: #000000; font-weight: bold;">for</span> VBD <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>xe vbd-list vm-uuid=<span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> ^uuid <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;VBD: <span style="color: #007800;">$VBD</span>&quot;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #000000; font-weight: bold;">`</span>xe vbd-param-get param-name=<span style="color: #7a0874; font-weight: bold;">type</span> <span style="color: #007800;">uuid</span>=<span style="color: #007800;">$VBD</span><span style="color: #000000; font-weight: bold;">`</span> = <span style="color: #ff0000;">&quot;CD&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
		<span style="color: #000000; font-weight: bold;">then</span>
			<span style="color: #007800;">CUR_VDI</span>=<span style="color: #000000; font-weight: bold;">`</span>xe vdi-list vbd-uuids=<span style="color: #007800;">$VBD</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> ^uuid <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">`</span>xe vdi-param-get <span style="color: #007800;">uuid</span>=<span style="color: #007800;">$CUR_VDI</span> param-name=is-a-snapshot<span style="color: #000000; font-weight: bold;">`</span>
			<span style="color: #000000; font-weight: bold;">then</span>
				<span style="color: #007800;">VDIS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$VDIS</span> <span style="color: #007800;">$CUR_VDI</span>&quot;</span>
			<span style="color: #000000; font-weight: bold;">else</span>
				<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;VDI is not a snapshot!&quot;</span>
				<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
			<span style="color: #000000; font-weight: bold;">fi</span>
			<span style="color: #007800;">CUR_VDI</span>=<span style="color: #ff0000;">&quot;&quot;</span>
		<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">done</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$VDIS</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> remove_vdi <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># This function will get a list of VDIs and remove them</span>
	<span style="color: #666666; font-style: italic;"># Carefull!</span>
	<span style="color: #000000; font-weight: bold;">for</span> VDI <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #000000; font-weight: bold;">@</span>
	<span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #000000; font-weight: bold;">if</span> xe vdi-destroy <span style="color: #007800;">uuid</span>=<span style="color: #007800;">$VDI</span>
		<span style="color: #000000; font-weight: bold;">then</span>
			<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Success in removing VDI <span style="color: #007800;">$VDI</span>&quot;</span>
		<span style="color: #000000; font-weight: bold;">else</span>
			<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Failure in removing VDI <span style="color: #007800;">$VDI</span>&quot;</span>
			<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
		<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> remove_template <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># This funciton will remove a template</span>
	<span style="color: #666666; font-style: italic;"># $1 template UUID</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Required UUID&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	xe template-param-set is-a-template=<span style="color: #c20cb9; font-weight: bold;">false</span> <span style="color: #007800;">uuid</span>=<span style="color: #007800;">$1</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">!</span> xe vm-uninstall <span style="color: #007800;">force</span>=<span style="color: #c20cb9; font-weight: bold;">true</span> <span style="color: #007800;">uuid</span>=<span style="color: #007800;">$1</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Failure to remove VM/Template&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> remove_all_template <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># This function will completely remove a template</span>
	<span style="color: #666666; font-style: italic;"># The steps are as follow:</span>
	<span style="color: #666666; font-style: italic;"># $1 is the UUID of the template</span>
	<span style="color: #666666; font-style: italic;"># Calculate its VDIs</span>
	<span style="color: #666666; font-style: italic;"># Remove the template</span>
	<span style="color: #666666; font-style: italic;"># Remove the VDIs</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;No Template UUID was supplied&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #666666; font-style: italic;"># We now collect the value of $VDIS</span>
	get_vdi <span style="color: #007800;">$1</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Failed to get VDIs for Template $1&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">!</span> remove_template <span style="color: #007800;">$1</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Failure to remove template $1&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">!</span> remove_vdi <span style="color: #007800;">$VDIS</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> create_all_snapshots <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #666666; font-style: italic;"># In this function we will run all over $LIST and create snapshots of each machine, keeping the UUID of it inside a file</span>
	<span style="color: #666666; font-style: italic;"># $@ - list of machines in the $LIST format</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$UUID_LIST_FILE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$UUID_LIST_FILE</span> <span style="color: #007800;">$UUID_LIST_FILE</span>.<span style="color: #007800;">$$</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #000000; font-weight: bold;">@</span>
	<span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #007800;">SNAP_UUID</span>=<span style="color: #000000; font-weight: bold;">`</span>take_snap_quiesce <span style="color: #800000;">${i%%:*}</span> <span style="color: #800000;">${i##*:}</span><span style="color: #000000; font-weight: bold;">`</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
		<span style="color: #000000; font-weight: bold;">then</span>
			<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Problem taking snapshot with quiesce for <span style="color: #007800;">${i%%:*}</span>&quot;</span>
			<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Attempting normal snapshot&quot;</span>
			<span style="color: #007800;">SNAP_UUID</span>=<span style="color: #000000; font-weight: bold;">`</span>take_snap <span style="color: #800000;">${i%%:*}</span> <span style="color: #800000;">${i##*:}</span><span style="color: #000000; font-weight: bold;">`</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$?&quot;</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
                	<span style="color: #000000; font-weight: bold;">then</span>
                        	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Problem taking snapshot for <span style="color: #007800;">${i%%:*}</span>&quot;</span>
				<span style="color: #007800;">SNAP_UUID</span>=<span style="color: #ff0000;">&quot;&quot;</span>
			<span style="color: #000000; font-weight: bold;">fi</span>
		<span style="color: #000000; font-weight: bold;">fi</span>
		stop_ha_template <span style="color: #007800;">$SNAP_UUID</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$SNAP_UUID</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$UUID_LIST_FILE</span>
	<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>Possible use will be like this:</p>
<blockquote><p>. /usr/local/bin/xen_functions.sh</p>
<p>create_all_snapshots `assign_all_uuids` &#038;> /tmp/snap_create.log</p></blockquote>


<p>Related posts:<ol><li><a href='http://run.tournament.org.il/quick-provisioning-of-virtual-machines/' rel='bookmark' title='Permanent Link: Quick provisioning of virtual machines'>Quick provisioning of virtual machines</a> <small>When one wants to achieve fast provisioning of virtual machines,...</small></li>
<li><a href='http://run.tournament.org.il/relocating-lvs-with-snapshots/' rel='bookmark' title='Permanent Link: Relocating LVs with snapshots'>Relocating LVs with snapshots</a> <small>Linux LVM is a wonderful thing. It is scalable, flexible,...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://run.tournament.org.il/xenserver-create-snapshots-for-all-machines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
