Hi,
Had a problem that I had a server name and it's IP and needed to make sure that the IP did not change.
Here is a small script to do that, pass the name and IP as parameters and it will give you back errorlevel according to the check (0 for OK).
============================================================
FOR /f "tokens=1,3 delims=: " %%A IN ('ping -n 1 %1') DO IF %%A==Reply set ip=%%B
If %2==%ip% goto ok
exit /B 1
:OK
exit /B 0
============================================================
Enjoy
Showing posts with label batch. Show all posts
Showing posts with label batch. Show all posts
13 July, 2015
29 January, 2015
creating m3u playlist automatically
Hi,
I'm updating my USB stick very frequently and the new car I got does not allow folder browsing only playlists. - very annoying.
But, this is not something that will stop me... after a lot of testing a created the following script, it will create a M3U file in each sub-directory (for now it only works with one level down).
So, there is PlayListCreator-Step1.cmd:
==========================================
del *.m3u /S /Q
dir /B /AD >DirList.txt
for /f "tokens=*" %%A in (DirList.txt) do (PlayListCreator-Step2.cmd "%%A")
I'm updating my USB stick very frequently and the new car I got does not allow folder browsing only playlists. - very annoying.
But, this is not something that will stop me... after a lot of testing a created the following script, it will create a M3U file in each sub-directory (for now it only works with one level down).
So, there is PlayListCreator-Step1.cmd:
==========================================
del *.m3u /S /Q
dir /B /AD >DirList.txt
for /f "tokens=*" %%A in (DirList.txt) do (PlayListCreator-Step2.cmd "%%A")
==========================================
And PlayListCreator-Step2.cmd:
==========================================
set root=%__CD__%
cd %1
dir /b /o:n *.mp3 > "%~1.m3u"
cd /d %root%
==========================================
Just save the content between the === to files and run PlayListCreator-Step1.cmd.
Enjoy...
15 February, 2013
Get machine IP via script (and check if it's up)
Hi,
I encountered a problem, I have a list of servers from AD and wanted to get the IP on each server.
It seems that this is not easy, I could not find a clean way to do it on the web.
As a batch fan I wrote a small script that get's, as an input, a list of names, ping them and echo out to a file the name and the IP (so you can import it to excel easily).
You need to prepare a file named list.txt with all the names to convert to IP.
Next, create 2 files:
STEP1.CMD
========================================
del pinged_list.txt /q
for /f %%A in (list.txt) do (step2.cmd %%A)
========================================
STEP2.CMD
========================================
ping %1 -n 1 -w 1| find "TTL=" > 1.txt
if %errorlevel% NEQ 0 goto end
for /f "tokens=1-3 delims= " %%A in (1.txt) do (echo %%C > 2.txt)
for /f "tokens=1-3 delims=:" %%A in (2.txt) do (echo %1, %%A >>pinged_list.txt)
del 2.txt /q
:end
del 1.txt /q
=========================================
run step1.cmd and wait to the pinged_list.txt file to be prepared.
Enjoy...
I encountered a problem, I have a list of servers from AD and wanted to get the IP on each server.
It seems that this is not easy, I could not find a clean way to do it on the web.
As a batch fan I wrote a small script that get's, as an input, a list of names, ping them and echo out to a file the name and the IP (so you can import it to excel easily).
You need to prepare a file named list.txt with all the names to convert to IP.
Next, create 2 files:
STEP1.CMD
========================================
del pinged_list.txt /q
for /f %%A in (list.txt) do (step2.cmd %%A)
========================================
STEP2.CMD
========================================
ping %1 -n 1 -w 1| find "TTL=" > 1.txt
if %errorlevel% NEQ 0 goto end
for /f "tokens=1-3 delims= " %%A in (1.txt) do (echo %%C > 2.txt)
for /f "tokens=1-3 delims=:" %%A in (2.txt) do (echo %1, %%A >>pinged_list.txt)
del 2.txt /q
:end
del 1.txt /q
=========================================
run step1.cmd and wait to the pinged_list.txt file to be prepared.
Enjoy...
07 September, 2010
Utilizing systeminfo to get info on a list of servers or workstation
Hi,
If you have a list of computers (servers or workstations) and need to get some info on them, for example Total Physical Memory you could use my script to get this info.
First put all the computer names in a file and name it servers.txt.
Then decide what property you want to get, the following properties are availble:
Host Name
OS Name:
OS Version
OS Manufacturer
OS Configuration
OS Build Type
Registered Owner
Registered Organization
Product ID
Original Install Date
System Boot Time
System Manufacturer
System Model
System Type
BIOS Version
Windows Directory
System Directory
Boot Device
System Locale
Input Locale
Time Zone
Total Physical Memory
Available Physical Memory
Virtual Memory: Max Size
Virtual Memory: Available
Virtual Memory: In Use
Page File Location(s)
Domain
Logon Server
(will work with only property that the output is 1 line)
The script:
===================================
@echo off
echo.
echo Type the SystemInfo attribute
echo you want to check:
set /P C=
del "%C%.txt"
for /f %%A in (servers.txt) do (
echo Server: %%A >> "%C%.txt"
systeminfo /s \\%%A | find "%C%:" >> "%C%.txt"
echo ------------------------------------------------------------------ >> "%C%.txt"
)
==================================
enjoy
If you have a list of computers (servers or workstations) and need to get some info on them, for example Total Physical Memory you could use my script to get this info.
First put all the computer names in a file and name it servers.txt.
Then decide what property you want to get, the following properties are availble:
Host Name
OS Name:
OS Version
OS Manufacturer
OS Configuration
OS Build Type
Registered Owner
Registered Organization
Product ID
Original Install Date
System Boot Time
System Manufacturer
System Model
System Type
BIOS Version
Windows Directory
System Directory
Boot Device
System Locale
Input Locale
Time Zone
Total Physical Memory
Available Physical Memory
Virtual Memory: Max Size
Virtual Memory: Available
Virtual Memory: In Use
Page File Location(s)
Domain
Logon Server
(will work with only property that the output is 1 line)
The script:
===================================
@echo off
echo.
echo Type the SystemInfo attribute
echo you want to check:
set /P C=
del "%C%.txt"
for /f %%A in (servers.txt) do (
echo Server: %%A >> "%C%.txt"
systeminfo /s \\%%A | find "%C%:" >> "%C%.txt"
echo ------------------------------------------------------------------ >> "%C%.txt"
)
==================================
enjoy
02 September, 2010
Simple Script to disable UAC on vista/W7
Hi,
The prompt for approval is annoying? Try this simple script in batch...
(It will restart the PC and you must run it with administrator privileges)
=======================
@echo off
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_dword /d 0 /f
if %errorlevel%==0 (goto restart)
echo Unable to set the registry key...
pause
goto end
:restart
shutdown -r -f -t 30 /c "UAC Disabled, Restarting..."
quit
:end
=======================
enjoy
The prompt for approval is annoying? Try this simple script in batch...
(It will restart the PC and you must run it with administrator privileges)
=======================
@echo off
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_dword /d 0 /f
if %errorlevel%==0 (goto restart)
echo Unable to set the registry key...
pause
goto end
:restart
shutdown -r -f -t 30 /c "UAC Disabled, Restarting..."
quit
:end
=======================
enjoy
26 August, 2010
XenServer disaster recovery script in batch
Hi all,
I wanted to make my life easier when the disaster will hit (and between you and me it allays a meter of time) so I wrote a menu driven disaster recovery script.
The script is covering:
You will need 2 more files that create your environment:
Note: in host_list.txt the role should be in lower letters (member/master)
To help you I saved it also as a GoogleDoc.
Any comments/improvements will be welcomed...
================================
Echo off
title "Xen Recover for 5.5 - at any time hit Cntrl+C and then Y to exit the script."
set user=[]
set password=[]
set server=[]
cls
echo This is a disaster recover script for Xen Server.
echo.
echo Host Infrastructure:
for /f "tokens=1,2 delims=," %%A in (Host_list.txt) do (echo Host: %%A - %%B)
echo.
echo Guest Machines:
for /f %%A in (VM_list.txt) do (echo VM: %%A)
echo.
echo.
echo is this OK ? (1-yes)
set /P C=
if %C%==1 goto continue
goto EOF
:continue
cls
echo Good.
echo What do you want to do ?
echo 1 - Recover from pool master failure
echo 2 - Recover from member failure
set /P C=
if %C%==1 goto master_failure
if %C%==2 goto member_failure
:master_failure
echo To which server to you want to transfer the pool master role ? (IP address only)
set /P C=
echo transfer pool master to %C%
pause
echo pool move to %C%
set server=%C%
echo on
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% pool-emergency-transition-to-master
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% pool-recover-slaves
Echo off
:master_failure_2
echo Type the new pool master server name: (case sensitive)
for /f "tokens=1,2 delims=," %%A in (Host_list.txt) do (
if %%B==member (echo Host: %%A)
)
set /P xenhostname=
set caller=master_failure_3
goto check_host
:member_failure_3
if "%host_ok%"=="yes" (goto member_failure_4)
echo The Host name is not on the list
pause
goto member_failure_2
set failed-host=%xenhostname%
goto power_reset
:member_failure
echo Which member server has failed ? (type the name - case sensitive)
echo Showing only members.
for /f "tokens=1,2 delims=," %%A in (Host_list.txt) do (
if %%B==member (echo Host: %%A)
)
echo.
echo It seems that the following host is down:
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% host-list host-metrics-live=false params=name-label
set /P xenhostname=
set caller=member_failure_2
goto check_host
:member_failure_2
if "%host_ok%"=="yes" (goto member_failure_3)
echo The Host name is not on the list
pause
goto member_failure
:member_failure_3
set failed-host=%xenhostname%
goto power_reset
:power_reset
echo resetting the power state on the machines that was on the failed host [%failed-host%]
pause
echo get host uuid
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% host-list name-label=%xenhostname% --minimal > host_uuid.txt
set /p host_uuid=
echo resetting power on VM's residing on %xenhostname% [uuid=%host_uuid%]
echo on
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-reset-powerstate resident-on=%host_uuid% --force --multiple
Echo off
goto VM_recover
:vm_recover
echo Which VM do you need to recover ?
for /f %%A in (VM_list.txt) do (echo %%A)
echo it seems that the following VM's were on the failed host:
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-list is-control-domain=false resident-on=%host_uuid% params=name-label
set /P vmname=
set caller=vm_recover_2
goto check_vm
:vm_recover_2
if "%vm_ok%"=="yes" (goto vm_recover_3)
echo The VM name is not on the list...
pause
goto vm_recover
:vm_recover_3
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-list name-label=%vmname% --minimal > vm_uuid.txt
set /p vm_uuid=
:vm_recover_4
echo Recover to which HOST ?
for /f %%A in (host_list.txt) do (echo %%A)
echo.
echo Note: %failed-host% has failed and cannot be choosen.
set /P xenhostname=
if "%xenhostname%"==%failed-host% (
echo %failed-host% has failed and cannot be choosen.
goto :vm_recover_4
)
set caller=vm_recover_5
goto check_host
:vm_recover_5
if "%host_ok%"=="yes" (goto vm_recover_6)
echo The HOST name is not on the list...
pause
goto vm_recover_4
:vm_recover_6
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% host-list name-label=%E% --minimal > host_uuid.txt
set /p host_uuid=
echo recover %vmname% [%vm_uuid%] on %xenhostname% [%host_uuid%]
echo on
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% xe vm-param-set uuid=%vm_uuid% affinity=%host_uuid%
Echo off
echo.
echo Recover another VM ? (1-yes)
set /P C=
if %C%==1 goto vm_recover
goto end
rem *** general functions ***
:check_host
set host_ok=
for /f "tokens=1 delims=," %%A in (Host_list.txt) do (
if "%xenhostname%"=="%%A" (set host_ok=yes)
)
goto %caller%
:check_vm
set vm_ok=
for /f %%A in (vm_list.txt) do (
if "%vmname%"=="%%A" (set vm_ok=yes)
)
goto %caller%
:end
rem *** cleanup ***
del host_uuid.txt /q
del vm_uuid.txt /q
pause
:EOF
echo *** written by snir hoffman http://snirh.blogspot.com ***
==========================================
I wanted to make my life easier when the disaster will hit (and between you and me it allays a meter of time) so I wrote a menu driven disaster recovery script.
The script is covering:
- Pool Master failure
- Host Member Failure
- resetting the power state of VM's
- Recovering them to another HOST
You will need 2 more files that create your environment:
- host_list.txt - all the hosts and their role, one each line. example: [servername, member]
- vm_list.txt - all the vm
Note: in host_list.txt the role should be in lower letters (member/master)
To help you I saved it also as a GoogleDoc.
Any comments/improvements will be welcomed...
================================
Echo off
title "Xen Recover for 5.5 - at any time hit Cntrl+C and then Y to exit the script."
set user=[]
set password=[]
set server=[]
cls
echo This is a disaster recover script for Xen Server.
echo.
echo Host Infrastructure:
for /f "tokens=1,2 delims=," %%A in (Host_list.txt) do (echo Host: %%A - %%B)
echo.
echo Guest Machines:
for /f %%A in (VM_list.txt) do (echo VM: %%A)
echo.
echo.
echo is this OK ? (1-yes)
set /P C=
if %C%==1 goto continue
goto EOF
:continue
cls
echo Good.
echo What do you want to do ?
echo 1 - Recover from pool master failure
echo 2 - Recover from member failure
set /P C=
if %C%==1 goto master_failure
if %C%==2 goto member_failure
:master_failure
echo To which server to you want to transfer the pool master role ? (IP address only)
set /P C=
echo transfer pool master to %C%
pause
echo pool move to %C%
set server=%C%
echo on
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% pool-emergency-transition-to-master
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% pool-recover-slaves
Echo off
:master_failure_2
echo Type the new pool master server name: (case sensitive)
for /f "tokens=1,2 delims=," %%A in (Host_list.txt) do (
if %%B==member (echo Host: %%A)
)
set /P xenhostname=
set caller=master_failure_3
goto check_host
:member_failure_3
if "%host_ok%"=="yes" (goto member_failure_4)
echo The Host name is not on the list
pause
goto member_failure_2
set failed-host=%xenhostname%
goto power_reset
:member_failure
echo Which member server has failed ? (type the name - case sensitive)
echo Showing only members.
for /f "tokens=1,2 delims=," %%A in (Host_list.txt) do (
if %%B==member (echo Host: %%A)
)
echo.
echo It seems that the following host is down:
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% host-list host-metrics-live=false params=name-label
set /P xenhostname=
set caller=member_failure_2
goto check_host
:member_failure_2
if "%host_ok%"=="yes" (goto member_failure_3)
echo The Host name is not on the list
pause
goto member_failure
:member_failure_3
set failed-host=%xenhostname%
goto power_reset
:power_reset
echo resetting the power state on the machines that was on the failed host [%failed-host%]
pause
echo get host uuid
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% host-list name-label=%xenhostname% --minimal > host_uuid.txt
set /p host_uuid=
echo resetting power on VM's residing on %xenhostname% [uuid=%host_uuid%]
echo on
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-reset-powerstate resident-on=%host_uuid% --force --multiple
Echo off
goto VM_recover
:vm_recover
echo Which VM do you need to recover ?
for /f %%A in (VM_list.txt) do (echo %%A)
echo it seems that the following VM's were on the failed host:
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-list is-control-domain=false resident-on=%host_uuid% params=name-label
set /P vmname=
set caller=vm_recover_2
goto check_vm
:vm_recover_2
if "%vm_ok%"=="yes" (goto vm_recover_3)
echo The VM name is not on the list...
pause
goto vm_recover
:vm_recover_3
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% vm-list name-label=%vmname% --minimal > vm_uuid.txt
set /p vm_uuid=
:vm_recover_4
echo Recover to which HOST ?
for /f %%A in (host_list.txt) do (echo %%A)
echo.
echo Note: %failed-host% has failed and cannot be choosen.
set /P xenhostname=
if "%xenhostname%"==%failed-host% (
echo %failed-host% has failed and cannot be choosen.
goto :vm_recover_4
)
set caller=vm_recover_5
goto check_host
:vm_recover_5
if "%host_ok%"=="yes" (goto vm_recover_6)
echo The HOST name is not on the list...
pause
goto vm_recover_4
:vm_recover_6
"C:\Program Files\Citrix\XenCenter\xe.exe" -s %server% -u %user% -pw %Password% host-list name-label=%E% --minimal > host_uuid.txt
set /p host_uuid=
echo recover %vmname% [%vm_uuid%] on %xenhostname% [%host_uuid%]
echo on
Echo off
echo.
echo Recover another VM ? (1-yes)
set /P C=
if %C%==1 goto vm_recover
goto end
rem *** general functions ***
:check_host
set host_ok=
for /f "tokens=1 delims=," %%A in (Host_list.txt) do (
if "%xenhostname%"=="%%A" (set host_ok=yes)
)
goto %caller%
:check_vm
set vm_ok=
for /f %%A in (vm_list.txt) do (
if "%vmname%"=="%%A" (set vm_ok=yes)
)
goto %caller%
:end
rem *** cleanup ***
del host_uuid.txt /q
del vm_uuid.txt /q
pause
:EOF
echo *** written by snir hoffman http://snirh.blogspot.com ***
==========================================
17 August, 2010
Xen Server Automatic Host backup script using batch
Hi,
You can never be too carefull, here is an automated backup script for xen server host.
Be careful, it can reach to 1G... (Mine did).
as always you will need a list file with the names of the xen hosts (case sensitive), name it host_list.txt.
and the following: (this will keep 2 versions, you can remove those lines if you want)
replace [] with your data.
====================================
for /f %%A in (host_list.txt) do (
del "D:\Backup\XenServer\OLD_%%A_Backup.bak" /q
ren D:\Backup\XenServer\%%A_Backup.bak Old_%%A_Backup.bak
"C:\Program Files\Citrix\XenCenter\xe.exe" -s [server ip] -u [user] -pw [password] host-backup host=%%A file-name=D:\Backup\XenServer\%%A_Backup.bak
)
====================================
You can never be too carefull, here is an automated backup script for xen server host.
Be careful, it can reach to 1G... (Mine did).
as always you will need a list file with the names of the xen hosts (case sensitive), name it host_list.txt.
and the following: (this will keep 2 versions, you can remove those lines if you want)
replace [] with your data.
====================================
for /f %%A in (host_list.txt) do (
del "D:\Backup\XenServer\OLD_%%A_Backup.bak" /q
ren D:\Backup\XenServer\%%A_Backup.bak Old_%%A_Backup.bak
"C:\Program Files\Citrix\XenCenter\xe.exe" -s [server ip] -u [user] -pw [password] host-backup host=%%A file-name=D:\Backup\XenServer\%%A_Backup.bak
)
====================================
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...
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...
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.
=====================================
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.
=====================================
20 May, 2010
Central Fortigate Backup script
Hi,
I have several sites with fortigate as the firewall and a lot of on the fly changes on them, I wrote a script for automatic backup of the fortigates, it uses the following tools:
- PLINK
- 7zip
You need to prepare a FTP site to backup to, I created the site on the machine that runs the backup and this way I can zip it up after the backup completes.
just run it once a day and it will keep history for each day.
change each [] field with your values.
===========================================================
echo off
set user=[username]
rd D:\Backup\Fortigate\Temp /s /q
md D:\Backup\Fortigate\Temp
:1st
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=2nd
goto start_bk
:2nd
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=3rd
goto start_bk
:3rd
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=7zip
goto start_bk
:start_bk
echo === Backing up %hostName% at %hostIP% ===
echo execute backup config ftp /fortigate/Temp/%hostname%_%hostIP%.conf [traget ftp ip] [ftp user] [ftp password] > Command.txt
plink -ssh %hostIP% -l %user% -pw %pass% -m D:\Work\Fortigates_Backup\Command.txt
del command.txt /q
echo.
goto %next%
:7zip
Set MONTH=%DATE:~4,2%
Set DAY=%DATE:~7,2%
Set YEAR=%DATE:~10,4%
7z.exe a -r "D:\Backup\Fortigate\FG_%DAY%-%MONTH%-%YEAR%.zip" D:\Backup\Fortigate\Temp\*.*
:end
====================================================================
have fun.
I have several sites with fortigate as the firewall and a lot of on the fly changes on them, I wrote a script for automatic backup of the fortigates, it uses the following tools:
- PLINK
- 7zip
You need to prepare a FTP site to backup to, I created the site on the machine that runs the backup and this way I can zip it up after the backup completes.
just run it once a day and it will keep history for each day.
change each [] field with your values.
===========================================================
echo off
set user=[username]
rd D:\Backup\Fortigate\Temp /s /q
md D:\Backup\Fortigate\Temp
:1st
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=2nd
goto start_bk
:2nd
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=3rd
goto start_bk
:3rd
set pass=[password]
set hostIP=x.x.x.x
set hostName=[Fortigate Name]
set next=7zip
goto start_bk
:start_bk
echo === Backing up %hostName% at %hostIP% ===
echo execute backup config ftp /fortigate/Temp/%hostname%_%hostIP%.conf [traget ftp ip] [ftp user] [ftp password] > Command.txt
plink -ssh %hostIP% -l %user% -pw %pass% -m D:\Work\Fortigates_Backup\Command.txt
del command.txt /q
echo.
goto %next%
:7zip
Set MONTH=%DATE:~4,2%
Set DAY=%DATE:~7,2%
Set YEAR=%DATE:~10,4%
7z.exe a -r "D:\Backup\Fortigate\FG_%DAY%-%MONTH%-%YEAR%.zip" D:\Backup\Fortigate\Temp\*.*
:end
====================================================================
have fun.
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...
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...
Subscribe to:
Posts (Atom)