ESX-script

Automated backup with VCB v0.3. (6/11/2009)

Problem: I want to do a full backup of the VM’s with VCB. I tried out vRanger, overkill for my use and to expensive. I looked at VISBU, but i dont like the fact that i have to install some 3. party application on my production-environment-esx-servers. So i made my own very dirty script that handles the backup.

Requirements:

vSphere PowerCLI

Powershell

unxutils (remember to reboot when installed)

The scripts:

runvcbbackup.bat

powershell.exe c:\scripts\vcbbackup.ps1
type vms.txt | c:\scripts\tail.exe -n +4 > vmstailed.txt
xargs -n 1 vcbbkp.bat < vmstailed.txt

vcbbackup.ps1

add-pssnapin VMware.VimAutomation.Core
connect-viserver virtualcenterserver.domain.tld
get-vm | select name > vms.txt

vcbbkp.bat

@echo off
set bkppath=d:\vms\
set scriptpath=c:\scripts
set vmpath=%bkppath%%1

echo %time% Backup of %1 started >> time.txt

cd C:\Progra~1\VMware\VMware~1\

rename %vmpath% %1-old
vcbMounter.exe -h virtualcenterserver.domain.tld -u username -p password -a name:%1 -t fullvm -r %vmpath% -m san

IF EXIST %vmpath%\*.vmx rd %vmpath%-old /s /q
IF EXIST %vmpath%\*.vmx echo %date% %time% Backup of %1 succeded >> %scriptpath%\succeded2backup.txt
IF NOT EXIST %vmpath%\*.vmx echo %date% %time% Backup of %1 failed >> %scriptpath%\failed2backup.txt
cd
echo %time% Backup of %1 ended >> %scriptpath%\time.txt

Download zip-fil containing the 3 files.

Changelog

Usage:

Edit runvcbbackup.bat and set the path to these scripts.

Edit vcbbackup.ps1 and put in your vc-server, username and password.

Edit vcbbkp.bat and put in vc-server, username, password and path-to-backupstorage.

Enter this i a powershell: set-executionpolicy RemoteSigned

Execute runvcbbackup.bat to se if the scripts works. If they do make a scheduled job that executes runvcbbackup.bat.

Note1: Use these scripts with care, and dont blame me if they fuck something up ;)

Note2: The script does not support vm-names with spaces. I use vmname.domain.tld.

Respond to this post