2007-04-06

Volume Shadow Copy / Backups

I have spent the last few days working on implementing a new backup strategy for my servers. I thought I would share the fruits of my efforts so that others who are trying to attain the same goals might work a bit less than I did.

My goals for the new backup plan:
1. A homogenous environment (don't need to use different software on each machine)
2. Easy to use
3. Preferably would use differencing technology that only uploads the bytes that have been changed in each file to the server on incremental backups.
4. Client-Server design would be nice (install server software on a backup server, client software on other machines and backup to a central location).
5. Able to backup ALL files on the selected drives as a consistent snapshot that could ideally be restored to a new hard drive, inserted in a new machine, and...be ready to go (no re-installing everything, setting everything up, and restoring the files to the correct locations!).

I found some sosftware that meets most of the requirements from Vembu called StoreGrid. It is a client-server solution that is VERY easy to configure. It backs up to a central server location. It meets all of my goals except for the consistent snapshot one. This software can even do remote backups over the Internet, so it is also going to help me with the clients that I support outside of my own office. They have a solutions that allows you to backup files that are in use, but that caused me major grief on my servers and did not provide a consistent snapshot of the drive.

I found a way to make it work by using Volume Shadow Service on Windows XP & Windows Server 2003. I found some posts that allowed me to create a snapshot of a drive and then mount the snapshot to a drive letter in the computer. The drawback? It took a bit of work to get everything set up, and for the XP machines, I had to tweak the scripts to get it to work. I also had a bit of trouble finding some of the executables that I needed for the scripts.

The scripts came from Adi at Microsoft.

vshadow.exe for Windows Server 2003 and for Windows XP is included with the Volume Shadow Copy Service SDK 7.2 from Microsoft:
Shadow Copy Service SDK 7.2 from Microsoft
The vshadow file extracts to (pick the correct one, they are different):
C:\Program Files\Microsoft\VSSSDK72\TestApps\vshadow\bin\release-server
C:\Program Files\Microsoft\VSSSDK72\TestApps\vshadow\bin\release-xp

You only need dosdev for the Windows XP setup. dosdev was a bit harder to find, but I found it in the Microsoft Product Support Reporting Tools (MPSRPT), the one I used was the Exchange version, I think some of the other ones have it, too. When you run this, it will place the dosdev file in the C:\WINDOWS\MPSReports\Exchange\bin folder.

The tools are here:
MPSReports for exchange

After you have the executables and the scripts, set your backup in Vembu to use Pre & Post commands.
Pre Command:
COMMAND: C:/some folder/createshadow.cmd
ARGUMENTS: c: b:
WORKING PATH: C:/some folder
TIME OUT: 60

Post Command:
COMMAND: C:/some folder/removeshadow.cmd
TIME OUT: 60

*Note that removeshadow is not included in the scripts listed below, it is created by the createshadow.cmd script when it runs.

Here is what is required...
**********************
***Windows XP***
dosdev.exe
vshadow.exe
createshadow.cmd
wait.bat

The contents of the scripts are here:
createshadow.cmd:
-----------------------------------------------------------------
REM BEGIN SCRIPT
setlocal
if NOT "%CALLBACK_SCRIPT%"=="" goto :IS_CALLBACK
set SOURCE_VOLUME=%1
set DESTINATION_VOLUME=%2
set CALLBACK_SCRIPT=%~dpnx0
set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd
%~dp0vshadow.exe -script=%TEMP_GENERATED_SCRIPT% -exec=%CALLBACK_SCRIPT% %SOURCE_VOLUME%
del /f %TEMP_GENERATED_SCRIPT%
@goto :EOF

:IS_CALLBACK
setlocal
call %TEMP_GENERATED_SCRIPT%
%~dp0dosdev.exe %DESTINATION_VOLUME% %SHADOW_DEVICE_1%

REM ***This drive will only be available until this script exits***

@echo. >%~dp0RemoveShadow.cmd
@echo %~dp0dosdev -r -d %DESTINATION_VOLUME%>>%~dp0RemoveShadow.cmd
@echo %~dp0\VSHADOW.EXE -ds=%SHADOW_ID_1%>>%~dp0RemoveShadow.cmd
@echo del /f %~dp0RemoveShadow.cmd>>%~dp0RemoveShadow.cmd

REM echo off

:Loop
@CALL wait.bat 10
fsutil fsinfo volumeinfo %DESTINATION_VOLUME%>%~dp0shadow_drive_details.txt
@if errorlevel 1 goto :EndS
@goto :Loop

:EndS

REM END SCRIPT
----------------------------------------------------------------------

wait.bat:
----------------------------------------------------------------------
REM BEGIN SCRIPT wait.bat
@ping 127.0.0.1 -n 2 -w 1000 > nul
@ping 127.0.0.1 -n %1% -w 1000> nul
REM END SCRIPT
----------------------------------------------------------------------
***********************


***********************
For Windows Server 2003:

vshadow.exe
createshadow.cmd

createshadow.cmd:
----------------------------------------------------------------------
REM BEGIN SCRIPT createshadow.cmd
setlocal
if NOT "%CALLBACK_SCRIPT%"=="" goto :IS_CALLBACK
set SOURCE_VOLUME=%1
set DESTINATION_VOLUME=%2
set CALLBACK_SCRIPT=%~dpnx0
set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd
%~dp0\vshadow.exe -nw -p -script=%TEMP_GENERATED_SCRIPT% -exec=%CALLBACK_SCRIPT% %SOURCE_VOLUME%
del /f %TEMP_GENERATED_SCRIPT%
@goto :EOF

:IS_CALLBACK
setlocal
call %TEMP_GENERATED_SCRIPT%
%~dp0\vshadow.exe -el=%SHADOW_ID_1%,%DESTINATION_VOLUME%
@echo.
@echo *******************************************
@echo To delete the shadow copy, run the command:
@echo VSHADOW.EXE -ds=%SHADOW_ID_1%
@echo *******************************************
@echo.
@echo.>%~dp0\RemoveShadow.cmd
@echo REM ******************************************* >>%~dp0\RemoveShadow.cmd
@echo REM To delete the shadow copy, run the command: >>%~dp0\RemoveShadow.cmd
@echo REM VSHADOW.EXE -ds=%SHADOW_ID_1% >>%~dp0\RemoveShadow.cmd
@echo REM ******************************************* >>%~dp0\RemoveShadow.cmd
@echo REM This will remove the Shadow Volume %DESTINATION_VOLUME% >>%~dp0\RemoveShadow.cmd
@echo REM This message will self destruct.>>%~dp0\RemoveShadow.cmd

@echo. >>%~dp0\RemoveShadow.cmd
echo %~dp0\VSHADOW.EXE -ds=%SHADOW_ID_1%>>%~dp0\RemoveShadow.cmd
echo %~dp0\VSHADOW.EXE -ds=%SHADOW_ID_1%>%~dp0\ShadowCleanup.cmd
echo del /f %~dp0\RemoveShadow.cmd>>%~dp0\RemoveShadow.cmd

REM END SCRIPT
------------------------------------------------------------------------