I was using vmWare Server 1.x to host our intranet site, scripted backup using vmCOM API, all worked well etc.
I had to reinstall the host OS so decided to move to Server 2.0 while i was at it, but i didnt check whether the currect backup script would work; it wont (no vmCOM in server2)
After looking around on google and not finding anything particulaly good i decided to wack one together myself using the vmWare VIX 1.6 API. The script is to be run from a Windows PC/host and afaik should work with both versions of server and all versions of workstation from 6+, and also ESX.
VIX API compatibility.
As you can see VIX is the only API which is fully supported accross all platforms, hense my choice. It does not currently work with ESXi as the only API for ESXi is VI remote.
This script is by no means finished, nor does it log errors very well, but it does work. Just thought id get it posted up on here so people who have came accros the same problem atleast have something working by means of backup. Oh and people can tidy up my mess too! (im by no means a scripter)
What it does:
Suspends the VM
Copies its files to a temp folder suing robocopy.
Starts the VM
Used 7z CLI to make a compressed archive. (Only on level 1 compression atm due to my server being slow, will add ability to change in ini file)
Appends steps to datestamped log file.
What everything does;
backup.bat - the main script.
run.bat - launches and recorded the output of backup.bat to the log file defined in the ini.
*.ini - defines the parameters.
Prerequisites:
VIX API installed on the PC you will be running the script from. - You will need to register on the vmware site to get this. It is located on the main download page for Server 2.0
Robocopy - http://www.microsoft.com/downloads/d...displaylang=en
To use;
Unzip files.
Create/Edit the ini file to your liking (i have included a couple to give you examples)
Edit "Run.bat" and chang the first line to point to your ini file.
Run "Run.bat"
What ive tested working;
Script run localy on windows server 2003 host with vmserver2
Script successfully backed up a Windows XP test machine, a Debian4.0 and JeOS 8.10 (Ubuntu's cut down vm)/
Not tested but should work;
Script run remotely on windows workstation
vmServer 1.x vmserver 2.0, workstation 6.x+, ESX
As ive said im not a scripter so would appreciate it if someone can take a look at this. How would i tidy up the "for /f "tokens=2 delims==" %%? in ('find..." bit. Is there a way to read multiple variables from an ini file without repeating commands? (Obviously i could set a variable for this but ill wait and see if theres a "proper" way to do it first)
Main Script:
Also i will be making the "Run.bat" able to recieve the ini file via CL like so; "run.bat" -ini=server1Code:@echo off for /f "tokens=1,2,3 delims=/- " %%x in ("%date%") do set DATESTAMP=%%z%%y%%x setlocal enableextensions for /f "tokens=2 delims==" %%? in ('find /i "HOST" ^< %INI%') do set HOST=%%? if "%HOST:~0,1%" equ " " set HOST=%HOST:~1% for /f "tokens=2 delims==" %%? in ('find /i "VMNAME" ^< %INI%') do set VMNAME=%%? if "%VMNAME:~0,1%" equ " " set VMNAME=%VMNAME:~1% for /f "tokens=2 delims==" %%? in ('find /i "VMDIR" ^< %INI%') do set VMDIR=%%? if "%VMDIR:~0,1%" equ " " set VMDIR=%VMDIR:~1% for /f "tokens=2 delims==" %%? in ('find /i "VMROOTPATH" ^< %INI%') do set VMROOTPATH=%%? if "%VMROOTPATH:~0,1%" equ " " set VMROOTPATH=%VMROOTPATH:~1% for /f "tokens=2 delims==" %%? in ('find /i "USER" ^< %INI%') do set USER=%%? if "%USER:~0,1%" equ " " set USER=%USER:~1% for /f "tokens=2 delims==" %%? in ('find /i "PASS" ^< %INI%') do set PASS=%%? if "%PASS:~0,1%" equ " " set PASS=%PASS:~1% for /f "tokens=2 delims==" %%? in ('find /i "DATASTORE" ^< %INI%') do set DATASTORE=%%? if "%DATASTORE:~0,1%" equ " " set DATASTORE=%DATASTORE:~1% for /f "tokens=2 delims==" %%? in ('find /i "TEMPDIR" ^< %INI%') do set TEMPDIR=%%? if "%TEMPDIR:~0,1%" equ " " set TEMPDIR=%TEMPDIR:~1% for /f "tokens=2 delims==" %%? in ('find /i "BACKUPDIR" ^< %INI%') do set BACKUPDIR=%%? if "%BACKUPDIR:~0,1%" equ " " set BACKUPDIR=%BACKUPDIR:~1% for /f "tokens=2 delims==" %%? in ('find /i "VIX" ^< %INI%') do set VIX=%%? if "%VIX:~0,1%" equ " " set VIX=%VIX:~1% for /f "tokens=2 delims==" %%? in ('find /i "ROBOCOPY" ^< %INI%') do set ROBOCOPY=%%? if "%ROBOCOPY:~0,1%" equ " " set ROBOCOPY=%ROBOCOPY:~1% for /f "tokens=2 delims==" %%? in ('find /i "COMPRESS" ^< %INI%') do set COMPRESS=%%? if "%COMPRESS:~0,1%" equ " " set COMPRESS=%COMPRESS:~1% for /f "tokens=2 delims==" %%? in ('find /i "LOGS" ^< %INI%') do set LOGS=%%? if "%LOGS:~0,1%" equ " " set LOGS=%LOGS:~1% echo. echo ------------------------------------------------------------------------------------------------ echo %TIME% Starting backup %VMNAME% echo ------------------------------------------------------------------------------------------------ echo. echo %TIME% Deleting temp files in %TEMPDIR%\%VMNAME% ... IF EXIST "%TEMPDIR%\%VMNAME%" rd "%TEMPDIR%\%VMNAME%" /S /Q md "%TEMPDIR%\%VMNAME%" echo %TIME% Suspending %VMNAME% for snapshot backup ... "%VIX%\vmrun" -T server -h %HOST% -u %USER% -p %PASS% suspend "%DATASTORE% %VMDIR%/%VMNAME%.vmx" echo %TIME% Suspended %VMNAME%, copying files to temp dir ... %robocopy% "%VMROOTPATH%\%VMDIR%" "%TEMPDIR%\%VMNAME%" /e /NP echo. echo %TIME% Copying completed. Starting %VMNAME% ... "%VIX%\vmrun" -T server -h %HOST% -u %USER% -p %PASS% start "%DATASTORE% %VMDIR%/%VMNAME%.vmx" echo %TIME% Startup complete. Compressing backup files for %VMNAME% and transfering to %BACKUPDIR% %COMPRESS% a -t7z -mx1 -mmt "%BACKUPDIR%\%VMNAME%_%DATESTAMP%.7z" "%TEMPDIR%\%VMNAME%\*.*" echo %TIME% Finished compressing. Deleting temp files in %TEMPDIR%\%VMNAME% ... rem rd "%TEMPDIR%\%VMNAME%" /S /Q echo %TIME% Completed! The archieve is located in %BACKUPDIR% echo ================================================================================================
Will do this ASAP.
But in the mean time here it is, please feel free to edit, copy and improve. But please do post back and hopefully with abit of work we will have a finished script to go in the wiki which should work for the forseeable future atleast.
//Looking further into it; if you want to use vmWare server 1.x you will need to edit the line starting "%VIX%\vmrun.exe ....." and add a "1" after "server" :- ""%VIX%\vmrun" -T server1 -h..."
If you want to use Workstation then please have a read through the VIX API manual and correct the command.


LinkBack URL
About LinkBacks




