How to use this to preserve full database schema version history in SVN

Jan 13, 2016 at 6:53 PM
Install Tortoise on your server. Run scriptdb once initially to get your files, then check that folder hierarchy into your SVN server using tortoise. Now the folder hierarchy is under source control management. Create a batch file, and schedule it to run with a sql agent job (make sure you use a proxy account with sufficient permissions):

@ECHO OFF
echo BATCH START
date /t
time /t
cd /d G:\DatabaseVersionControl\
IF %ERRORLEVEL% NEQ 0 goto END
G:\DatabaseVersionControl\ScriptDB\scriptDB.exe -con:server=MyServerName;database=master;trusted_connection=yes -outDir:MyServerName [-p] -ScriptAsCreate -ScriptAllDatabases -Purge -Permissions -NoEncrypted -noPauseIfError > scriptdblog.txt 2> scriptdberrors.txt
REM Repeat the above for every server you want to fully script out
IF %ERRORLEVEL% NEQ 0 goto END
svn cleanup
IF %ERRORLEVEL% NEQ 0 goto END
for /f "tokens=2* delims=" %%f in ('svn status %1 ^| find "?"') do svn add "%%~sdpnxf"
IF %ERRORLEVEL% NEQ 0 goto END
for /f "tokens=2* delims=" %%f in ('svn status %1 ^| find "!"') do svn delete "%%~sdpnxf"
IF %ERRORLEVEL% NEQ 0 goto END
svn commit -m "Automatic commit" %1
IF %ERRORLEVEL% NEQ 0 goto END


REM echo %ERRORLEVEL%
echo BATCH END
date /t
time /t

:END
exit %errorlevel%