1

I'm working on modifying a batch file used for backups. When it runs it creates a new shadowcopy, mounts it, backups what it should, and dismounts it. What I would like to do is have it delete the shadowcopy it created. I don't what to delete existing shadowcopys for forensic reasons. Here is the section of code I'm having and issue with.

:DeleteNewSCopy
REM : Locates then removes the last created shadowcopy.
SET ShadowID=
FOR /F "usebackq tokens=1,2* delims=:" %%A IN (`FINDSTR /I /C:"Shadow Copy ID:" %TempFile%`) DO SET ShadowID=%%B

IF NOT "%ShadowID%" == "" (
    REM : Last ShadowCopy ID was found, Nuke it.
    vssadmin delete shadows /Shadow=%ShadowID%
) ELSE (
    ECHO No ShadowCopy ID found.
)
GOTO :EOF

The FOR line seems to be working correctly. When I ECHO out the %ShadowID% during run-time I get:

ShadowID:  {4fcb026a-08fe-4a34-b198-da7560db57bf}

But the line to delete the shadowcopy fails with:

Error: Invalid option value.

In the command line I can set ShadowID to have the same string and run the command without issue, so I seems like it should work in the batch file.

Any assistance will be appreciated.

Drake
  • 21
  • 1
  • 3

1 Answers1

0

I found that the problem wasn't with the code it was with how I was pulling the variable ShadowID. It had a leading space that needed to be removed. I used a solution posted by Foumpie to get it fixed.

https://stackoverflow.com/a/12089079/8272143

Drake
  • 21
  • 1
  • 3