wbadmin backup all local drives

I'm trying to find a one-size fits all wbadmin script that I can deploy to a variety of Server 2008 R2 servers.

The catch I'm having is that whilst all of the servers have a C:, some have an E:, some an E: and an F: and some have just an F:.

The following command:

wbadmin enable backup -addtarget:\\backup1\Backups -schedule:23:00 -systemState -allCritical -vssFull -user:[email protected] -password:ladidada -quiet

Only backs up the C: and I don't see any options in wbadmin to back up all the local drives. And of course, if I try shoot the problem with a machine gun (by adding -include:c:,d:,e:,f:...etc) then we get ERROR - The path specified by 'g:' was not found.

Please don't tell me that I have to enumarate all the local drives and do it that way. Is there ANY way to tell wbadmin to include all local drives when backing up?


Here's a variation that automatically avoids cd/dvd. It deliberately backs up hard drives only.

@echo off

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

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

This forms part of a scheduled task which is why wbadmin start is used rather than wbadmin enable.

The bits of interest here are "drivetype=3" and using usebackq (required).

Mark's code was helpful in tracking this down.

The if statements remove the last comma or comma and colon if they exist. Couldn't think of an easier way to do this. %%a is copied into _drive so it can be trimmed to the first 2 characters (C:) using the :~0,2 syntax.