ESXi 5.0 Host Backup Script


I wrote up a batch script to backup the ESXi 5.0 host configuration every night, email the backup report and remove the old archive folders that is older than 7 days.

To make it work, you need to:

1) install the vCLI and add its bin folder to the system PATH

2) Add all your ESXi servers to C:\Scripts\servers.txt

3) Setup the sendmail

4) Schedule the backup job

The report looks like this (there are no folders older than 7 days so far)

image

———————————————————————————————————

@ECHO OFF

REM ====Backup ESXi hosts=======================================================
cd C:\Scripts\
mkdir %Date:~-10,2%-%Date:~-7,2%-%Date:~-4,4%
cd %Date:~-10,2%-%Date:~-7,2%-%Date:~-4,4%

echo Subject: ESXi Backup Report > C:\Scripts\log.txt
echo.>> C:\Scripts\log.txt
date /t >> C:\Scripts\log.txt

for /F “tokens=*” %%A in (C:\Scripts\servers.txt) do (
vicfg-cfgbackup.pl –server %%A –username root –password ********* –save %%A >> C:\Scripts\log.txt 2>&1
)

echo. >> C:\Scripts\log.txt

REM ====Remove archive folders older then 7 days==================================
echo +++++++++++++++++++++++++++++++++++++++++++ >> C:\Scripts\log.txt
echo The following old folders have been removed >> C:\Scripts\log.txt
forfiles /p C:\scripts /d -7 /c “cmd /c if @isdir==TRUE echo @file & RD /Q /S @file” >> C:\Scripts\log.txt 2>&1

REM ====Email the backup report=================================================
echo. >> C:\Scripts\log.txt
C:\Scripts\sendmail -t < C:\Scripts\log.txt

download_icon

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s