Ticket #13: ShadowBox.bat

File ShadowBox.bat, 2.9 KB (added by petej, 18 months ago)

ShadowBox?.bat, an example of how to use Shadow Copy, vshadow.exe

Line 
1::ShadowBox.bat
2::A script to help Box Backup backup locked files on Windows.
3::
4::This code was stolen from: 
5::  http://blogs.msdn.com/adioltean/archive/2005/01/05/346793.aspx
6::  and related links.
7::2007-07-26 Stolen by pjalajas at tebucosafe dot com
8::Please, suggestions welcome!
9::
10::Usage:
11::Sorry, you have lots of site-specific editing to do below, for now.
12::   Look at all the "set" commands below...
13::Put this batch file and vshadow.exe in the same directory, like in
14::   D:\Program Files\Box Backup\
15::Add a Scheduled Task to run this daily or weekly as a System Admin.
16
17setlocal
18
19@REM test if we are called by VSHADOW
20if NOT "%CALLBACK_SCRIPT%"=="" goto :IS_CALLBACK
21
22@REM
23@REM Get the source and destination path
24@REM
25
26::set SOURCE_DRIVE_LETTER=%~d1
27set SOURCE_DRIVE_LETTER=D:
28::set SOURCE_RELATIVE_PATH=%~pnx1
29::set SOURCE_RELATIVE_PATH=Data\Finance\Accounts\filename.ext
30::set DESTINATION_PATH=%2
31::set DESTINATION_PATH=D:\Data\Finance\Accounts\ShadowBoxCopies\filename.ext
32
33@REM
34@REM Create the shadow copy - and generate env variables into a temporary script.
35@REM
36@REM Then, while the shadow is still live
37@REM recursively execute the same script.
38@REM
39
40@echo ...Determine the scripts to be executed/generated...
41
42::set CALLBACK_SCRIPT=%~dpnx0
43::Use the name of THIS .bat file...
44set CALLBACK_SCRIPT=D:\Program Files\Box Backup\ShadowBox.bat
45set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd
46
47@echo ...Creating the shadow copy...
48
49::Is this broken...?  Should we take out '%~dp0\' ?
50"%~dp0\vshadow.exe" -script=%TEMP_GENERATED_SCRIPT% -exec="%CALLBACK_SCRIPT%" %SOURCE_DRIVE_LETTER%
51
52del /f %TEMP_GENERATED_SCRIPT%
53
54@goto :EOF
55
56:IS_CALLBACK
57setlocal
58
59@REM
60@REM This generated script should set the SHADOW_DEVICE_1 env variable
61@REM
62
63@echo ...Obtaining the shadow copy device name...
64
65call %TEMP_GENERATED_SCRIPT%
66
67@REM
68@REM This should copy the file to the right location
69@REM
70
71@echo ...Copying from the shadow copy to the destination path...
72
73::copy "%SHADOW_DEVICE_1%\%SOURCE_RELATIVE_PATH%" %DESTINATION_PATH%
74::
75::No trailing slashes...
76::
77::QuickBooks
78set SDIR=\Data\Finance\Accounts
79set DDRIVE=D:
80set DDIR=\Data\Finance\Accounts\ShadowBoxCopies
81::Just the QB filename base, no extension, like "YourCompanyName", not "YourCompanyName.qbw"...
82set QBFILEBASE=filename
83copy "%SHADOW_DEVICE_1%%SDIR%\%QBFILEBASE%.qbw" "%DDRIVE%%DDIR%\%QBFILEBASE%.qbw" 
84copy "%SHADOW_DEVICE_1%%SDIR%\%QBFILEBASE%.qbw.TLG" "%DDRIVE%%DDIR%\%QBFILEBASE%.qbw.TLG" 
85copy "%SHADOW_DEVICE_1%%SDIR%\%QBFILEBASE%.qbw.ND" "%DDRIVE%%DDIR%\%QBFILEBASE%.qbw.ND" 
86::
87::Exchange Server
88set SDIR=\Program Files\Exchsrvr
89set DDIR=\Program Files\Exchsrvr\ShadowBoxCopies
90copy "%SHADOW_DEVICE_1%%SDIR%\mdbdata" "%DDRIVE%%DDIR%\mdbdata\"
91del /f /q "%DDRIVE%%DDIR%\Mailroot\vsi 1\queue\*.*"
92copy "%SHADOW_DEVICE_1%%SDIR%\Mailroot\vsi 1\queue" "%DDRIVE%%DDIR%\Mailroot\vsi 1\queue"