@echo off
SET primaryservername=
for /F "tokens=3 skip=3" %%a in ('"%ProgramFiles%\DoubleTake\Creo\bin\reg" query HKLM\Software\Creo\Araxi\Settings\Default\System /v PrimaryNodeName') do set primaryservername=%%a
:ConfigureRepsetsMenu

cls
echo.
echo.
echo DoubleTake Kodak Installer - Replication Set Configuration Menu
echo.
echo.
echo Please select the action you wish to perform:
echo.
echo [1] Create Oracle DB Replication Set (Primary Server Only)
echo.
echo [2] Create Job Folder Replication Set (Job Home Server)
echo.
echo [0] Do Nothing and Exit
echo.
echo.
set CHOICE=
SET /P CHOICE=Type in your selection and press ENTER: 
echo.
echo.

if "%CHOICE%"=="1" goto checkIfPrimary

if "%CHOICE%"=="2" goto CreateJobRepset

if "%CHOICE%"=="0" goto :eof

goto ConfigureRepsetsMenu

:checkIfprimary
if /I "%primaryservername%"=="%computername%" goto CreateOracleRepset
echo.
echo Creation of Oracle Replication Set must only be done on the Prinergy Primary.
echo This server is not detected as the Primary.
pause
goto :ConfigureRepsetsMenu

*************************************************************
::Repset creation
*************************************************************

:CreateOracleRepset
cls
echo. 
echo Creating Oracle Replication Set.
echo Run this only on the Prinergy Primary Server.
echo.
echo If PrinergyDB replication set exists, it has to be deleted first
echo    using the Double-Take Management Console. Consider
echo    modifying the repset using DTMC.
echo.
echo Please select the action you wish to perform:
echo.
echo [1] Start Creation of Oracle Replication Set.
echo.
echo [0] Do Nothing and go to Main Menu

echo.
echo.
set CHOICE=
SET /P CHOICE=Type in your selection and press ENTER: 
echo.
echo.

if "%CHOICE%"=="1" goto StartCreateOracleRepset

goto :ConfigureRepsetsMenu

:StartCreateOracleRepset

set datadrive=
echo.
set /P datadrive=Enter the drive where the Database  resides (usually G: or J:):
if "%datadrive%"=="" cls && goto StartCreateOracleRepset
if not exist %datadrive% echo Drive %datadrive% does not exist && pause && goto :StartCreateOracleRepset
if exist %datadrive%\Orant goto :OracleRepset
if exist %datadrive%\Oracle goto :OracleRepset

echo Oracle was not found in %datadrive% && pause && goto :StartCreateOracleRepset

:OracleRepset
echo.
echo Creating replication set . . 

if exist %temp%\prinergydbrepsetsetup.txt del %temp%\prinergydbrepsetsetup.txt >nul

::Common repset
echo source "%primaryservername%"; > "%temp%\prinergydbrepsetsetup.txt"
echo repset create "PrinergyDB"; >> "%temp%\prinergydbrepsetsetup.txt"


if /I NOT "%oracle_sid%"=="creo" goto 10Grepset 

:8iRepset
echo repset rule add "%araxihome%\Automation\bin\Rules" include, recursive; >>  "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%araxihome%\Automation\bin\Rules\*.exe" exclude; >>  "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%araxihome%\Automation\bin\Rules\*.dll" exclude; >>  "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%SystemDrive%\Ora816\DATABASE" include, recursive; >> "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%SystemDrive%\Ora816\DATABASE\*.exe" exclude; >> "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%SystemDrive%\Ora816\rdbms\trace" include, recursive; >> "%temp%\prinergydbrepsetsetup.txt"
if /I "%SystemDrive%"=="D:" echo repset rule add "E:\Orant" include, recursive; >> %temp%\prinergydbrepsetsetup.txt >> "%temp%\prinergydbrepsetsetup.txt"
if /I "%SystemDrive%"=="C:" echo repset rule add "%SystemDrive%\Orant" include, recursive; >> %temp%\prinergydbrepsetsetup.txt >> "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%datadrive%\Orant" include, recursive; >> "%temp%\prinergydbrepsetsetup.txt"

goto createPrimRepset

:10GRepset
echo repset rule add "%ProgramFiles%\Kodak\RBA\bin\Rules" include, recursive; >>  "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%ProgramFiles%\Kodak\RBA\bin\Rules\*.exe" exclude; >>  "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%ProgramFiles%\Kodak\RBA\bin\Rules\*.dll" exclude; >>  "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%SystemDrive%\Oracle\10.2.0\database" include, recursive; >> "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%SystemDrive%\Oracle\10.2.0\database\*.exe" exclude; >> "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%SystemDrive%\Oracle\10.2.0\RDBMS\trace" include, recursive; >> "%temp%\prinergydbrepsetsetup.txt"
if /I "%SystemDrive%"=="D:" echo repset rule add "E:\Oracle" include, recursive; >> "%temp%\prinergydbrepsetsetup.txt"
if /I "%SystemDrive%"=="C:" echo repset rule add "C:\Oracle\oradata" include, recursive; >> "%temp%\prinergydbrepsetsetup.txt"
echo repset rule add "%datadrive%\Oracle" include, recursive; >> "%temp%\prinergydbrepsetsetup.txt"

:createPrimRepset

::Add Oracle Backup zip file location
call "%ProgramFiles%\DoubleTake\Creo\bin\GetOraclePath.cmd" >> "%temp%\prinergydbrepsetsetup.txt"

echo repset save; >> "%temp%\prinergydbrepsetsetup.txt"
echo Done.
echo.
echo Running DoubleTake utility with the following command line: 
echo.
echo %programfiles%\DoubleTake\dtcl -f %temp%\prinergydbrepsetsetup.txt
"%programfiles%\DoubleTake\dtcl" -f "%temp%\prinergydbrepsetsetup.txt"
echo.
echo Done.
echo.
echo All further replication set configuration is done from the DoubleTake
echo Management Console.
pause

goto :ConfigureRepsetsMenu


:CreateJobRepset
cls
echo Creating Job Folder Replication Set.
echo Run this only on the Job Home Server.
echo.
echo If PrinergyJobs replication set exists, it has to be deleted first
echo   using the Double-Take Management Console. Consider
echo   modifying the repset using DTMC.
echo.
echo Please select the action you wish to perform:
echo.
echo [1] Start Creation of PrinergyJobs Replication Set.
echo.
echo [0] Do Nothing and go to Main Menu

echo.
echo.
set CHOICE=
SET /P CHOICE=Type in your selection and press ENTER: 
echo.
echo.

if "%CHOICE%"=="1" goto StartCreateJobRepset

goto :ConfigureRepsetsMenu

:StartCreateJobRepset
set jobspath=
echo Note down the paths of the Jobs folders that need to be replicated
echo (your tertiary server might only have one). For a Jobs folder in
echo J:\Volume1\Jobs, enter "J:\Volume1". For J:\Jobs, enter "J:"
echo.
set /P jobspath=Enter the path where your Jobs folder is (Usually G: or J:)
if "%jobspath%"=="" goto CreateJobRepset
if exist %jobspath%\Jobs goto ActuallyCreateJobRepset
echo %jobspath%\Jobs does not exist. Check the path you entered.
pause
goto CreateJobRepset

:ActuallyCreateJobRepset

if exist "%temp%\prinergyjobrepsetsetup.txt" del "%temp%\prinergyjobrepsetsetup.txt"
echo source "%computername%"; > "%temp%\prinergyjobrepsetsetup.txt"
echo repset create "PrinergyJobs"; >> "%temp%\prinergyjobrepsetsetup.txt"

:AddEachJobFolder
echo Adding %jobspath%\Jobs to the replication set . . .
echo.
echo repset rule add "%jobspath%\Jobs" include, recursive; >> "%temp%\prinergyjobrepsetsetup.txt"
echo repset rule add "%jobspath%\Jobs\*\System\*Working" exclude, recursive; >> "%temp%\prinergyjobrepsetsetup.txt"
echo repset rule add "%jobspath%\Jobs\Network Trash Folder" exclude, recursive; >> "%temp%\prinergyjobrepsetsetup.txt"

:MoreFolder
SET CHOICE=
SET /P CHOICE=Do you want to replicate another jobs folder? (y/N): 

if /I "%CHOICE%"=="n" goto SaveRepset
if /I "%CHOICE%"=="y" goto AddJobDrive
goto MoreFolder

:AddJobDrive
set jobspath=
set /P jobspath=Enter the path of the next Jobs folder (Usually G: or J:)
if "%jobspath%"=="" goto MoreFolder
if exist %jobspath%\Jobs goto AddEachJobFolder
echo %jobspath%\Jobs does not exist. Check the path you entered.
pause
goto MoreFolder

:SaveRepset
echo repset save; >> "%temp%\prinergyjobrepsetsetup.txt"
echo.
echo Running DoubleTake utility with the following command line: 
echo.
echo %programfiles%\DoubleTake\dtcl -f %temp%\prinergyjobrepsetsetup.txt
"%programfiles%\DoubleTake\dtcl" -f "%temp%\prinergyjobrepsetsetup.txt"
echo.
echo Done.
echo.
echo All further replication set configuration is done from the DoubleTake
echo Management Console.
pause

goto :ConfigureRepsetsMenu


:eof
