We are using ScriptDB to generate SQL files from a live Production system.
Before applying the files to a new system, we need to exclude some of the files and apply batch changes to the remaining files.
So here is what we did:
- Issue ScriptDB to generate SQL files for each DB Object
- Prepare an exclusion list; listing files we will like to skip
- Ran our batch file
Here is what the batch file does
- It reads an exception file; that lists the objects to be skipped
- If the entry should be skipped it makes a copy of it.
- The copy file has the same name as the original file with .bak appended
- The Original file is then removed
And, so what we end up is a folder that has the files we need and the files we want to skipped delineated by the .bak extention
@ECHO OFF @REM Please make sure to keep the EnableDelayedExpansion Setlocal EnableDelayedExpansion IF %1.==. ( Echo Please specify Source Folder as the first argument Goto End ) set folderSource=%1 set folderBase=%folderSource% echo FolderBase is !folderBase! @REM The Full Location of the except text file set "exceptSourceFolder=." set "exceptSourceFile=skippedFiles.txt" set "exceptSourceFileFull=%exceptSourceFolder%\%exceptSourceFile%" echo Exception Source File is !exceptSourceFileFull! set /p DUMMY=Hit ENTER to Start Processing Skipped Files set "BAKEXT=.bak" echo %exceptSourceFileFull% for /f %%f in (%exceptSourceFileFull%) do ( ECHO Processing Except entry %%f ... set _filename=%folderBase%\%%f ECHO Processing File !_filename! @REM Get full file name by adding except file name to base folder set _fullFileTest=!_filename! ECHO "Full Name of File !_fullFileTest!" @REM Get Backup file name @REM set "fullFileTestBak=%fullFileTest%%BAKEXT%" set "_fullFileTestBak=!_filename!%BAKEXT%" ECHO "Test File (BAK) !_fullFileTestBak!" @REM Copy file to backup file if exist !_fullFileTest! ( @REM If Backup file alreay exists, please delete it if exist "!_fullFileTestBak!" ( echo "Removing backup file !_fullFileTestBak_! ..." del !_fullFileTestBak! echo "Removed backup file !_fullFileTestBak! ) echo "Copy file !_fullFileTest! as backup file !_fullFileTestBak! ..." copy !_fullFileTest! !_fullFileTestBak! 1>NUL echo "Del file !_fullFileTest! ..." del !_fullFileTest! ) else ( @REM Echo Skipped File not found - !_fullFileTest! ) echo. echo. ) set /p DUMMY=Hit ENTER to Exit Processing Skipped Files Goto End :End
- Please keep in mind that you need the “Setlocal EnableDelayedExpansion“
- And, that instead of using % to access local variables , we use !
Here is the folder tree that ScriptDB generates for us.
Sample Exclusion File
Looking for something else, but felt like Leanne Rimes.
Here she sings Reba McEntire’s The Greatest Man I Never Knew.