Showing posts with label snapshot. Show all posts
Showing posts with label snapshot. Show all posts

04 August, 2010

Automatic script for Xen Coalesce (gain space back after using snapshots)

If you are using snapshots in XenServer you may noticed a spaced beed used on the storage that you cannot explained.
This is due to using snapshots. After you create the initial snapshot xen will continue writing to it even if it is not there.
To reclaim the space the VM's VDI need to go a proccess named "Coalesce" which integrates the data from the snapshot into the original VDI.

I used article CTX123400 to base my script on.
Also you will need to download "plink".

3 files:
  1. VM_List.txt - a list of the machine names (case sensitive)
  2. Step1.cmd
  3. Step2.cmd

Step1.cmd: replace [] with your own data
==========================
echo off
set user=[user]
set password=[password]
set server=[server ip]
del log_Coalesce.txt /q
for /f %%A in (vm_list.txt) do (step2.cmd %%A >>log_Coalesce.txt)
==========================

Step2.cmd:
==========================
title ***** Working on %1 *****
echo ***** Start working on %1 *****
echo.echo Start at:
echo %date% - %time%
set vm_uuid=
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-list name-label="%1" --minimal > vm_uuid.txt
set /p vm_uuid=

plink -ssh %server% -l %user% -pw %password% coalesce-leaf -u %vm_uuid%
echo.
echo %date% - %time%
echo ***** End working on %1 *****
echo.
============================


Enjoy

25 July, 2010

Delete all snapshots by name (XenServer)

I posted a blog a while back on how to delete all snapshots from SR.
I found it not working 100%, so I wrote a new script that deletes all Snapshots by name.
So if you use the backup script I wrote you can use this as a pre-step to delete old snapshots.

Here it is:
====================================================

echo === deleting old snapshot ===
set user=[user]
set password=[password]
set server=[IP]
echo Start at:
echo %date% - %time%
:start
C:\Progra~1\Citrix\XenCenter\xe.exe -s %server% -u %user% -pw %Password% template-list name-label=4Backup --minimal > Old_tempates.txt
for /f "tokens=1 delims=," %%G in (Old_tempates.txt) do (
if [%%G] EQU [] (goto end) else (
C:\Progra~1\Citrix\XenCenter\xe.exe -s %server% -u %user% -pw %Password% template-param-set is-a-template=false uuid=%%G
C:\Progra~1\Citrix\XenCenter\xe.exe -s %server% -u %user% -pw %Password% vm-uninstall uuid=%%G force=true
goto start
)
)

:end
=================================================

enjoy...

11 May, 2010

Delete all snapshots in a SR (XenServer)

Hi,

Wrote a little script to centrally delete all snapshots from a SR on XenServer.
I noticed that although you delete a snapshot an entry still remains on the SR.
Since I have 1 main SR I wrote a script to delete all of them before the backup process begins (later when it will be ready I'll post it).

================================================
echo === deleting old snapshot ===
echo Start at:
echo %date% - %time%
:start
C:\Progra~1\Citrix\XenCenter\xe.exe -s [Pool Master / Server IP] -u [user] -pw [password] vdi-list is-a-snapshot=true sr-uuid=[sr uuid] --minimal > vdi.txt
for /f "tokens=1 delims=," %%G in (vdi.txt) do (
if [%%G] EQU [] goto end
C:\Progra~1\Citrix\XenCenter\xe.exe -s [Pool Master / Server IP] -u [user] -pw [password] vdi-destroy uuid=%%G
echo.
goto start
)

:end
=================================================

and it works great...