I've been tasked with a massive automation project, of which WBAdmin is a small part of it. I've been trawling Google for two days now, finding snippets to assist with this. I am an amateur batch programmer and often rely on bits & pieces to help compile my own, tailored scripts.
The batch file needs to be able to backup all of the local drives (not mapped drives, optical drives, flash drives, etc.), with the exception of C:, in an Amazon Web Services Windows Server 2008 R2/2012 R2 environment.
Bonus points if it can backup each drive to its own .VHD file.
Code: Select all
@echo Off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
:Title
title WBAdmin
:Colour
color 0A
:Message.
@echo Checking for existing drives...
@echo.
set remotebackup=\\backupserver\path
for /F "usebackq eol=: skip=1 tokens=1" %%a in (
'wmic logicaldisk where "drivetype=3" get deviceid'
) do (
set "_drive=%%a:"
set "_HDL=!_HDL!!_drive:~0,2!,"
)
if "%_HDL:~-1%"=="," (set _HDL=%_HDL:~0,-1%)
if "%_HDL:~-2%"==",:" (set _HDL=%_HDL:~0,-2%)
echo Found: %_HDL%
WBADMIN START BACKUP -backuptarget:%remotebackup% -include:!_HDL! -allCritical -vssCopy -quiet -systemState
Through selective commenting, I've narrowed down the first issue to these two lines...
Code: Select all
:if "%_HDL:~-1%"=="," (set _HDL=%_HDL:~0,-1%)
:if "%_HDL:~-2%"==",:" (set _HDL=%_HDL:~0,-2%)
Any assistance rendered would be greatly appreciated.
Thank you.
Kind regards,
Nic