rsyncing from Windows 2003 shadow copies.

Craig Hammond
2006-09-14T09:21:23Z

Hi,
Hopefully this isn't duplicating info. If so, sorry for the noise.

I tried searching through old posts to this list about this issue, but
couldn't find anything that worked.
Below is a script I have put together that lets you rsync from a Windows
2003 shadow copy without having to copy files out of it first.
You can link the shadow copy to either a drive letter or to a folder.
You then rsync from there. The shadow copy is then deleted when the
script finishes.

Hopefully this helps someone.

you need vshadow.exe which is part of the VSS SDK which is a free
download from MS.
http://www.microsoft.com/downloads/details.aspx?FamilyID=0B4F56E4-0CCC-4
626-826A-ED2C4C95C871&displaylang=en

I'm sure this can be improved on. I welcome any feedback.


SHADOWRSYNC.CMD

setlocal

@REM test if we are called by shadowrsync.cmd
if NOT "%CALLBACK_SCRIPT%"=="" goto :IS_CALLBACK

@REM
@REM Set these variables to what you need.
@REM SHADOW_DRIVE_LETTER is an existing drive you want to shadow
@REM
@REM MAP_SHADOW_TO needs to be either a drive letter that isn't
@REM currently in use, or an empty directory
@REM eg.  x:   or  c:\temp\shadowcopy
@REM

set SHADOW_DRIVE_LETTER=D:
set MAP_SHADOW_TO=X:

@REM
@REM Create the shadow copy - and generate env variables into a
temporary script.
@REM Then resursively come back into this script.

set CALLBACK_SCRIPT=%~dpnx0
set TEMP_GENERATED_SCRIPT=GeneratedTempScript.cmd

@echo ...Create the shadow copy...

vshadow.exe -nw -p -script=%TEMP_GENERATED_SCRIPT%
-exec=%CALLBACK_SCRIPT% %SHADOW_DRIVE_LETTER%

del /f %TEMP_GENERATED_SCRIPT%

@goto :EOF

:IS_CALLBACK
setlocal

@REM Get the vshadow temp variables.

call %TEMP_GENERATED_SCRIPT%

@REM Map the drive to the shadow copy
vshadow -el=%SHADOW_ID_1%,%MAP_SHADOW_TO%

@REM Now do your rsync thing
rsync   blah blah blah blah........


@REM Delete the shadow
vshadow -ds=%SHADOW_ID_1%