Skip to content

Instantly share code, notes, and snippets.

@boxbackup-bot
Created May 19, 2019 10:06
Show Gist options
  • Save boxbackup-bot/40eae7e0ac8945d025d7915197d7a4b6 to your computer and use it in GitHub Desktop.
Save boxbackup-bot/40eae7e0ac8945d025d7915197d7a4b6 to your computer and use it in GitHub Desktop.
Trac issue 13 attachment
::ShadowBox.bat
::A script to help Box Backup backup locked files on Windows.
::
::This code was stolen from:
:: http://blogs.msdn.com/adioltean/archive/2005/01/05/346793.aspx
:: and related links.
::2007-07-26 Stolen by pjalajas at tebucosafe dot com
::Please, suggestions welcome!
::
::Usage:
::Sorry, you have lots of site-specific editing to do below, for now.
:: Look at all the "set" commands below...
::Put this batch file and vshadow.exe in the same directory, like in
:: D:\Program Files\Box Backup\
::Add a Scheduled Task to run this daily or weekly as a System Admin.
setlocal
@REM test if we are called by VSHADOW
if NOT "%CALLBACK_SCRIPT%"=="" goto :IS_CALLBACK
@REM
@REM Get the source and destination path
@REM
::set SOURCE_DRIVE_LETTER=%~d1
set SOURCE_DRIVE_LETTER=D:
::set SOURCE_RELATIVE_PATH=%~pnx1
::set SOURCE_RELATIVE_PATH=Data\Finance\Accounts\filename.ext
::set DESTINATION_PATH=%2
::set DESTINATION_PATH=D:\Data\Finance\Accounts\ShadowBoxCopies\filename.ext
@REM
@REM Create the shadow copy - and generate env variables into a temporary script.
@REM
@REM Then, while the shadow is still live
@REM recursively execute the same script.
@REM
@echo ...Determine the scripts to be executed/generated...
::set CALLBACK_SCRIPT=%~dpnx0
::Use the name of THIS .bat file...
set CALLBACK_SCRIPT=D:\Program Files\Box Backup\ShadowBox.bat
set TEMP_GENERATED_SCRIPT=GeneratedVarsTempScript.cmd
@echo ...Creating the shadow copy...
::Is this broken...? Should we take out '%~dp0\' ?
"%~dp0\vshadow.exe" -script=%TEMP_GENERATED_SCRIPT% -exec="%CALLBACK_SCRIPT%" %SOURCE_DRIVE_LETTER%
del /f %TEMP_GENERATED_SCRIPT%
@goto :EOF
:IS_CALLBACK
setlocal
@REM
@REM This generated script should set the SHADOW_DEVICE_1 env variable
@REM
@echo ...Obtaining the shadow copy device name...
call %TEMP_GENERATED_SCRIPT%
@REM
@REM This should copy the file to the right location
@REM
@echo ...Copying from the shadow copy to the destination path...
::copy "%SHADOW_DEVICE_1%\%SOURCE_RELATIVE_PATH%" %DESTINATION_PATH%
::
::No trailing slashes...
::
::QuickBooks
set SDIR=\Data\Finance\Accounts
set DDRIVE=D:
set DDIR=\Data\Finance\Accounts\ShadowBoxCopies
::Just the QB filename base, no extension, like "YourCompanyName", not "YourCompanyName.qbw"...
set QBFILEBASE=filename
copy "%SHADOW_DEVICE_1%%SDIR%\%QBFILEBASE%.qbw" "%DDRIVE%%DDIR%\%QBFILEBASE%.qbw"
copy "%SHADOW_DEVICE_1%%SDIR%\%QBFILEBASE%.qbw.TLG" "%DDRIVE%%DDIR%\%QBFILEBASE%.qbw.TLG"
copy "%SHADOW_DEVICE_1%%SDIR%\%QBFILEBASE%.qbw.ND" "%DDRIVE%%DDIR%\%QBFILEBASE%.qbw.ND"
::
::Exchange Server
set SDIR=\Program Files\Exchsrvr
set DDIR=\Program Files\Exchsrvr\ShadowBoxCopies
copy "%SHADOW_DEVICE_1%%SDIR%\mdbdata" "%DDRIVE%%DDIR%\mdbdata\"
del /f /q "%DDRIVE%%DDIR%\Mailroot\vsi 1\queue\*.*"
copy "%SHADOW_DEVICE_1%%SDIR%\Mailroot\vsi 1\queue" "%DDRIVE%%DDIR%\Mailroot\vsi 1\queue"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment