As a follow-up to my Snapshotting with the XenServer 5.0 SDK post, I’ve written a PowerShell snapin that will allow you to take and revert snapshots with XenServer. You can download the source code and binaries here. You must have the .NET Framework 3.5 installed before you can use it. To install the snapin you will need to run the following command after you’ve downloaded and extracted the ZIP file:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe /i XenServerSnapshotPSSnapIn.dll
Then you can open up your PowerShell console and enter the following to take a snapshot of your virtual machine named Bluemoon, which by the way is my favorite beer!
Add-PSSnapin XenServerSnapshot*
Checkpoint-VM -Hostname 192.168.0.2 -Username root -Password qwerty -VM Bluemoon -Snapshot BluemoonBackup
If you decide you’d like to revert to this snapshot you can do this:
Restore-VM -Hostname 192.168.0.2 -Username root -Password qwerty -VM Bluemoon -Snapshot BluemoonBackup
And before I leave the office for the night, here are a few things to note:
- The cmdlets return true if they were able to execute successfully, otherwise they return false.
- Virtual machine names are case-sensitive.
- PowerShell must be installed to compile the source. XenAPI.net is included with the download.
- I’ve made a few tweaks to this code from the original version.
Added 09-March-2009: The snapshot feature in XenServer requires a VHD-on-EXT3 storage repository. To change the default repository to EXT3, please see http://support.citrix.com/article/ctx116324. Alternatively, the following script can be used:
dev=`cat /etc/xensource-inventory | grep DEFAULT_SR_PHYSDEVS | cut -d ‘=’ -f2 | grep -o -E “[^'].*[^']“`
sr_uuid=`xe sr-list type=lvm | grep uuid | cut -d ‘:’ -f2 | cut -c 2-`
pbd_uuid=`xe pbd-list sr-uuid=$sr_uuid | grep -E ‘^uuid.*’ | cut -d ‘:’ -f2 | cut -c 2-`
inst_uuid=`cat /etc/xensource-inventory | grep INSTALLATION_UUID | cut -d ‘=’ -f2 | grep -o -E “[^'].*[^']“`
xe pbd-unplug uuid=$pbd_uuid
xe sr-destroy uuid=$sr_uuid
new_sr_uuid=`xe sr-create content-type=”local SR” host-uuid=$inst_uuid type=ext device-config-device=$dev shared=false name-label=”Local File SR”`
pool_id=`xe pool-list | grep uuid | cut -d ‘:’ -f2 | cut -c 2-`
xe pool-param-set default-SR=$new_sr_uuid uuid=$pool_id
xe pool-param-set suspend-image-SR=$new_sr_uuid uuid=$pool_id
#echo $dev
#echo $sr_uuid
#echo $pbd_uuid
#echo $inst_uuid
#echo $new_sr_uuid
#echo $pool_id
Feel free to post a comment here if you have any feedback. Enjoy!
Recent Comments