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...

21 July, 2010

Remote enable RDP on 2003 and XP

Remote desktop is not enabled by default with Windows XP and Win 2003 Server. 
However, you can connect through the network to a remote registry and enable it.
The key you need is :
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server
 

Change fdenyTSconnections from 1 to 0 and then remotely connect to the PC you need. 

You can also do "reg add \\[machine name]\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server /v fdenyTSconnections /t REG_DWORD /d 0 /f"
replacing [] woth your remote machine name.


I do not need to tell you that you need admin rights on the remote machine to do this...



19 July, 2010

Automatic script for Zip and delete files

I have a SQL backup directory and wanted a script to auto zip the files and delete them after a succesful zipping.

Here you go (using 7-zip):
==============================
FOR %%f in (*.bak) do (
7z.exe a %%f.7z  %%f
if %errorlevel%==0 (del %%f /q)
)
==============================

easy, no ?

08 July, 2010

Live Xen Backup using a batch job

Hi,

I like batch jobs more than VBS, I'm old fashion. :)
I wrote a script to backup Xen Server guests machines using batch.

The script will clean old snapshots with a single SR, then will try to create a snapshot with  quiesce (using VSS) and if not successful, will do a regular backup.

It contains 4 files:
1. VM_List.exe - the list of the vm names you want to backup (one per line)
2. Step1.cmd - the file you need to run, will enumerate the list of machines to backup
3. Step2.cmd - a command to delete all the old snapshots (more complicated that it sounds)
4. Step3.cmd - the actual backup script

and now the content of the files (VM_List.exe I believe you can create yourself):
Replace [] with your data.

Step1.cmd:
=====================================
echo off
set server=[pool master ip]
set user=root
set password=[password]
call XenBackup-Snapshots-step2.cmd > log_snap.txt
for /f %%A in (vm_list.txt) do (XenBackup-Snapshots-step3.cmd %%A >>log_snap.txt)
=====================================

Step2.cmd: (I assume you have 1 SR, if you have more just replicate this script per SR)
=====================================
echo === deleting old snapshot ===
echo Start at:
echo %date% - %time%
:start
C:\Progra~1\Citrix\XenCenter\xe.exe -s %server% -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 %server% -u %user% -pw %Password% vdi-destroy uuid=%%G
echo.
goto start
)
:end
=====================================

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

set snapshot-type=vm-snapshot-with-quiesce
:snapshot
C:\Progra~1\Citrix\XenCenter\xe.exe -s %server% -u %user% -pw %Password% %snapshot-type% new-name-label=backup uuid=%vm_uuid% > template_uuid.txt
set /p template_uuid=

set C=-
set N=
:loop
if !template_uuid:~0^,1! equ !C! (
set /a N+=1
)
if "!template_uuid:~1!" neq "" (
set template_uuid=!template_uuid:~1!
goto :loop
)
if !N! NEQ 4 do (
if %snapshot-type%==vm-snapshot goto no_snap else
set snapshot-type=vm-snapshot
goto snapshot
)

C:\Progra~1\Citrix\XenCenter\xe.exe -s %server% -u %user% -pw %Password% template-export template-uuid=%template_uuid% filename=d:\VM_Backup\%1.xva
echo.

:no_snap
echo NO SNAPSHOT !!!
:emd
echo.
echo %date% - %time%
echo ***** End working on %1 *****
echo.

=====================================

07 July, 2010

Automated internet speed check (using external FTP)

Hi,

I wanted to check the internet speed every week to be sure that we don't have any reduction from what the ISP should give us.

Asked the ISP for a FTP location and wrote a script that gives me a log each week with a download/upload speed.

The script has 2 files:
1. the FTP script
2. the CMD file

Instructions:
- name the ftp script transfer.txt
- replace the [] in transfer.txt with your info
- create a file for transfer and save it as c:\temp\TestFile.dat. (I used Lan Speed Test)
- You can edit the script to fit your environment

CMD file:
===========================================
echo off

rem *** create a unique log file by date ***
Set MONTH=%DATE:~4,2%
Set DAY=%DATE:~7,2%
Set YEAR=%DATE:~10,4%
set output=%YEAR%-%MONTH%-%DAY%.txt

echo The test was performed on the %DATE% at %TIME% > %output%
echo. >> %output%

rem *** run the test ***
ftp -s:Transfer.txt > ftp_output.txt

rem *** extract the important lines from the log ***
for /f "tokens=1,2,3,4,5,6,7 delims= " %%A in (ftp_output.txt) do (
if "%%A"=="ftp:" (echo %%A %%D %%G >> %output%)
)
====================================================
after you have the file you can mail it or just archive it.

Transfer.txt (replace the [] with your info):
====================================================
open [your.ftp.server]
[Username]
[password]
put c:\temp\TestFile.dat TestFile.dat
get TestFile.dat c:\temp\TestFile.dat
quit
====================================================

the log file would look like this:
====================================================
The test was performed on the Tue 07/06/2010 at 11:30:10.78

ftp: received 2780.83Kbytes/sec.

ftp: sent 1874.44Kbytes/sec.
====================================================

Bye...

04 July, 2010

Difference between Microsoft Access Runtime and Retail

Hi,

One of my clients asked me to give him a list of all the machines that runs MS Access Retail and list of MS Access Run-time.

I looked and looked and couldn't find any differences between the versions. The files are the same, the DLL's are the same. I was frustrated.

I used procmon.exe from sysinternal and found that there is no difference in the actual files but only registry settings !!!

Here there are:

[HKEY_CLASSES_ROOT\Licenses\73A4C9C1-D68D-11d0-98BF-00A0C90DC8D9\11.0\Runtime]
@="rldvasjwmvjfrcatkskctmtjahdnkccdgjds"


[HKEY_CLASSES_ROOT\Licenses\73A4C9C1-D68D-11d0-98BF-00A0C90DC8D9\11.0\Retail]
@="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"