+ Post New Thread
Results 1 to 13 of 13
Thin Client and Virtual Machines Thread, vmWare Backup Script (Server 2, Workstation, possibly ESX) in Technical; I was using vmWare Server 1.x to host our intranet site, scripted backup using vmCOM API, all worked well etc. ...
  1. #1


    Join Date
    Oct 2006
    Posts
    3,413
    Thank Post
    184
    Thanked 356 Times in 285 Posts
    Rep Power
    149

    vmWare Backup Script (Server 2, Workstation, possibly ESX)

    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:
    Code:
    @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 ================================================================================================
    Also i will be making the "Run.bat" able to recieve the ini file via CL like so; "run.bat" -ini=server1
    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.
    Attached Files Attached Files
    Last edited by j17sparky; 7th November 2008 at 05:32 PM.

  2. #2
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,987
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    107
    I would be very interested in any development on this. We have just started looking at moving some servers onto the free ESXi and I am wondering about backups. I nearly died when I was given the backup exec agent price so I am looking for alternatives.
    Discussing it with Ric earlier it did sound like reasonable enough to treat them as a normal machine and have a template server vm to restore to but I would like to see other methods in action.

    If I get time tommorow I will have a look at the script and see if I can get my head round it. One thing I would like to do is convert it to VBScript as I find that easier to read, even if it might end up bulkier
    Last edited by ChrisH; 5th November 2008 at 02:29 PM.

  3. #3
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,987
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    107
    I have been looking at this today and couldnt find the VIX 1.6 API. There doesnt seem to be a download link and topics on their forums are no help. There doesnt seem to be much positivity about backing up ESX either but I want to see that for myself :P .

  4. #4


    Join Date
    Oct 2006
    Posts
    3,413
    Thank Post
    184
    Thanked 356 Times in 285 Posts
    Rep Power
    149
    Heres the VIX API - you're right, its bloody hard to find that.

    Virtual Machine Automation SDKs - VMware

  5. #5
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,987
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    107
    I was looking for the 1.6 you mentioned. That links to 1.1.5 is this correct?


    Looks like I definately need 1.6 as there is no vmrun in this version.


    edit 2!
    Now I have read your post carefully and other documentation this isnt going to do what I wanted as I will mostly be working with ESXi. Serves me right for not reading carefully enough but I will keep my eye on it for future developments.
    Last edited by ChrisH; 7th November 2008 at 02:51 PM.

  6. #6


    Join Date
    Oct 2006
    Posts
    3,413
    Thank Post
    184
    Thanked 356 Times in 285 Posts
    Rep Power
    149
    Quote Originally Posted by ChrisH View Post
    I was looking for the 1.6 you mentioned. That links to 1.1.5 is this correct?


    Looks like I definately need 1.6 as there is no vmrun in this version.


    edit 2!
    Now I have read your post carefully and other documentation this isnt going to do what I wanted as I will mostly be working with ESXi. Serves me right for not reading carefully enough but I will keep my eye on it for future developments.
    Sorry, was in a rush so saw VIX and didnt look at the version number.

    You will have to register to get the VIX API. Its on the main download page for Server 2.


    From reading about i believe the only API you can use with ESXi is VI. (VI perl, VI python? etc). I would be interested to hear if you find anything on ESXi as i was planning on using that but have settled (atleast until i get more time) on server 2 on a windows host
    Last edited by j17sparky; 7th November 2008 at 05:34 PM.

  7. #7
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,987
    Thank Post
    120
    Thanked 283 Times in 261 Posts
    Rep Power
    107
    I have it but I didn't read your original post about ESXi which is what I have been experimenting with. I am currently playing with the backup script on the VMware forums for backing up using VI Remote.

  8. #8


    Join Date
    Oct 2006
    Posts
    3,413
    Thank Post
    184
    Thanked 356 Times in 285 Posts
    Rep Power
    149

  9. #9

    Join Date
    May 2009
    Location
    Copenhagen
    Posts
    1
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Question

    Quote Originally Posted by j17sparky View Post

    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"
    Hi there,

    I'm testing vmware 2.0.1 on both Linux and Windows platform. Om Linux there is no problems for me with backup, but on Windows 2003 R2 server I'm having difficulties.

    My ini file:

    Code:
    ;
    ; DO NOT include trailing \ (slash)
    
    
    ; IP of host, if the script is running on same PC as vmserver put https://127.0.0.1:8333/sdk
    HOST=https://127.0.0.1:8333/sdk
    
    ; Name of VM (vmx)
    VMNAME=SBS_2003_server
    
    ; Path to VM root
    VMROOTPATH=C:\Virtual Machines
    
    ; VM dir name
    VMDIR=SBS_2003_Server
    
    ; Username with permissions over vmServer
    USER=Administrator
    
    ; Password
    PASS=PASSWORD
    
    ; Name of datastore enclosed in [ ] ie [Virtual Machines in d]
    DATASTORE=[standard]
    
    ; Temp working dir for files
    TEMPDIR=C:\backuptemp
    
    ; Dir to copy compressed archive to
    BACKUPDIR=C:\backups\Virtual Machines
    
    ; Path to vmWare VIX API folder, normally "C:\Program Files\VMware\VMware VIX"
    VIX=C:\Program Files\VMware\VMware VIX
    
    ; Path to robocopy
    ROBOCOPY=C:\Program Files\Windows Resource Kits\robocopy.exe
    
    ; Path to 7Z CLI
    COMPRESS=C:\Program Files\7-Zip\7z.exe
    
    ; Path to log files
    LOGS=C:\vmpub\backup_log
    My run.bat:

    Code:
    @echo off
    SET INI=SBS_2003_Server.ini
    
    setlocal enableextensions
    
    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 "LOGS" ^< %INI%') do set LOGS=%%?
    if "%LOGS:~0,1%" equ " " set LOGS=%LOGS:~1%
    
    echo Backup of %VMNAME% started @ %TIME% on %DATE%
    
    for /f "tokens=1,2,3 delims=/- " %%x in ("%date%") do set DATESTAMP=%%z%%y%%x
    
    backup.bat >> "%LOGS%\%VMNAME%\%VMNAME%_%DATESTAMP%.txt"
    Echo Completed @ %TIME% on %DATE%
    pause
    Can you see where I'm making the error

  10. #10


    Join Date
    Oct 2006
    Posts
    3,413
    Thank Post
    184
    Thanked 356 Times in 285 Posts
    Rep Power
    149
    Quote Originally Posted by Denbert View Post
    Hi there,

    I'm testing vmware 2.0.1 on both Linux and Windows platform. Om Linux there is no problems for me with backup, but on Windows 2003 R2 server I'm having difficulties.

    First thing which jumps out at me is there is a space in your folder path. Give that a shot first.


    Unfortunatly we have moved to a full SAN-Xen solution so i wont be doing any more with this script.

  11. #11

    Join Date
    Jul 2009
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Did you find out if the space in your folder path was the problem?
    I have a space in mine too and it won't work...

  12. #12


    Join Date
    Oct 2006
    Posts
    3,413
    Thank Post
    184
    Thanked 356 Times in 285 Posts
    Rep Power
    149
    Quote Originally Posted by dtangen View Post
    Did you find out if the space in your folder path was the problem?
    I have a space in mine too and it won't work...
    Im fairly sure this is what the problem is, i tend not to use spaces for this reason. The script certainly works, infact its still in use now; been running for over 6 months and hasnt failed yet.

  13. #13

    Join Date
    Jul 2009
    Posts
    2
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Ok, did you change the names of the VMs/folders or did you put som kind of symbol like " or ' inside the paths?

    Thanks for your reply.

SHARE:
+ Post New Thread

Similar Threads

  1. VMWare ESX and USB Dongles
    By JamesC in forum Thin Client and Virtual Machines
    Replies: 9
    Last Post: 25th February 2013, 01:39 PM
  2. VMWare ESX NIC Load Balancing problem
    By JamesC in forum Thin Client and Virtual Machines
    Replies: 8
    Last Post: 17th September 2010, 12:16 PM
  3. VMware ESX (and ESXi) date bug - 12th August
    By pete in forum Thin Client and Virtual Machines
    Replies: 6
    Last Post: 16th August 2008, 06:24 PM
  4. VMware ESX / MS Virtual Server 2005
    By Andi in forum Thin Client and Virtual Machines
    Replies: 4
    Last Post: 7th August 2008, 09:40 AM
  5. VMWare ESX 3.5 - book recommendation
    By Paid_Peanuts in forum Thin Client and Virtual Machines
    Replies: 3
    Last Post: 16th April 2008, 10:37 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •