@ECHO on :EnvVar :: Set batch file environment variables @setlocal enableextensions ::Set Date and Time (DT is the variable) for /f "tokens=1-8 delims=::./ " %%A in ('echo %DATE% %TIME%') do set DT=%%B-%%C-%%D_%%E%%F Echo %DATE% %Time% :: Set the hostname of the 3par array set TPDSYSNAME= :: Set the location of the pwfile created with "setpassword -saveonly -file" set TPDPWFILE=C:\Program Files (x86)\Hewlett-Packard\HP 3PAR CLI\bin\3paradm.pwd :: Force all commands to execute without confirmation set TPDFORCE=1 :: Add the path of the 3PAR cli bin folder to the path set PATH=C:\Program Files (x86)\Hewlett-Packard\HP 3PAR CLI\bin;%PATH% :: Set system specific variables :: Set the servername for the server in Set SourceServerName= :: Set the name of the Remote Copy Group on the 3PAR Set RCG_NAME= :: Identifying the name of the Remote Copy log file. set RCopyLOG=D:\3parlogs\RemoteCopy\%RCG_NAME%_rcopy-sync_%DT%.txt :: Identifying the name of the Remote Copy log file. set RCopyStatusLOG=D:\3parlogs\RemoteCopy\%RCG_NAME%_rcopy-status.txt :: This will reflect the name of the scheduled task to launch the script to enter the Oracle DB into hot backup mode. set SHB=%SourceServerName%_SHB :: This will reflect the name of the scheduled task to launch the script to take the Oracle DB out of hot backup mode. set EHB=%SourceServerName%_EHB :: Sets the name of the text file in d:\3parlogs on the Oracle database server that will be generated once the DB is in hot backup .mode. set SHBlog= %SourceServerName%-SHB_complete.txt :: Set the name of the text file in d:\3parlogs on the Oracle database server that will be generated when the DB is taken out of hot backup mode. set EHBlog=%SourceServerName%-EHB_complete.txt :: This log file will be used as a trigger on whether the SHB and EHB tasks ran. set SchTskSHBLOG=D:\3parlogs\RemoteCopy\%RCG_NAME%_SHBTask.txt set SchTskEHBLOG=D:\3parlogs\RemoteCopy\%RCG_NAME%_EHBTask.txt :: Email Settings: :: Set the name of the SMTP Server set SMTP=wwwsmtp.wwwint.corp set SSMC= set EmailTo='','','' :: Sets the errorlevel to 0 which is the default code on the 3PAR for a successful operation set ERRORLEVEL=0 echo ----- Show Job Specific Environment Variables for Validation ----- >> %RCopyLOG% set TPDSYSNAME >> %RCopyLOG% set TPDPWFILE >> %RCopyLOG% set TPDFORCE >> %RCopyLOG% set PATH >> %RCopyLOG% set SourceServerName >> %RCopyLOG% set RCopyLOG >> %RCopyLOG% set RCopyStatusLOG >> %RCopyLOG% set SHB >> %RCopyLOG% set EHB >> %RCopyLOG% set SHBlog >> %RCopyLOG% set EHBlog >> %RCopyLOG% set SchTskSHBLOG >> %RCopyLOG% set SchTskEHBLOG >> %RCopyLOG% set SMTP >> %RCopyLOG% Set EmailTo >> %RCopyLOG% set ERRORLEVEL >> %RCopyLOG% echo -------------------------------------------------------------------------------------------------------- >> %RCopyLOG% :startrcopy echo ----- Start rcopygroup %RCG_NAME% on %TPDSYSNAME% ----- >> %RCopyLOG% Echo %DATE% %Time% >> %RCopyLOG% cli startrcopygroup %RCG_NAME% >> %RCopyLOG% echo wait 10 seconds… >> %RCopyLOG% timeout /t 10 /nobreak echo %DATE% %Time% - Validate rcopygroup %RCG_NAME% has been started >> %RCopyLOG% cli showrcopy groups %RCG_NAME% >> %RCopyLOG% echo -------------------------------------------------------------------------------------------------------- >> %RCopyLOG% echo - Directory listing of \\%SourceServerName%\d$\3parlogs\ >> %RCopyLOG% ::Delete the existing Oracle backup mode complete trigger files echo %DATE% %Time% >> %RCopyLOG% dir \\%SourceServerName%\d$\3parlogs\ >> %RCopyLOG% echo %DATE% %Time% - Delete the existing Oracle hotbackup trigger files in \\%SourceServerName%\d$\3parlogs\ >> %RCopyLOG% del /f /q \\%SourceServerName%\d$\3parlogs\%SHBlog% >> %RCopyLOG% del /f /q \\%SourceServerName%\d$\3parlogs\%EHBlog% >> %RCopyLOG% echo %DATE% %Time% - Verify that the %SHBlog% and %EHBlog% trigger files have been deleted in \\%SourceServerName%\d$\3parlogs\ >> %RCopyLOG% dir \\%SourceServerName%\d$\3parlogs\ >> %RCopyLOG% echo -------------------------------------------------------------------------------------------------------- >> %RCopyLOG% :starthotbackup echo ----- Validate that the Start Hot Backup Scheduled task on %SourceServerName% is in a "Ready" state ----- >> %RCopyLOG% echo %DATE% %Time% >> %RCopyLOG% schtasks /query /S %SourceServerName% /FO list /TN %SHB% >> %RCopyLOG% echo %DATE% %Time% - Launch the Start Hot Backup Scheduled task on %SourceServerName% >> %RCopyLOG% schtasks /run /s %SourceServerName% /tn %SHB% > %SchTskSHBLOG% ::This section will check the log to ensure that the scheduled task was started, since errorlevels cannot be used and it does not pipe out failures to the log file this is checking for SUCCESS, if it is not then it will email the failure. FOR /F "tokens=*" %%A IN ('FINDSTR /N "SUCCESS" "%SchTskSHBLOG%"') DO ( GOTO :waithotbackup ) :end GOTO :SHBFailed echo -------------------------------------------------------------------------------------------------------- >> %RCopyLOG% :waithotbackup echo ----- Wait 30 seconds for the Oracle hotbackup operation to complete ----- >> %RCopyLOG% echo %DATE% %Time% >> %RCopyLOG% timeout /t 30 /nobreak If exist \\%SourceServerName%\d$\3parlogs\%SHBlog% GOTO :rcsync else GOTO :waithotbackup echo %DATE% %Time% - The Start Hot Backup Scheduled task has completed >> %RCopyLOG% echo -------------------------------------------------------------------------------------------------------- >> %RCopyLOG% :rcsync echo ----- Launch syncronization %RCG_NAME% from ROC to CHI ----- >> %RCopyLOG% echo %DATE% %Time% >> %RCopyLOG% cli syncrcopy %RCG_NAME% >> %RCopyLOG% echo %DATE% %Time% - Waiting 10 seconds for the snapshots on %TPDSYSNAME% to complete and for replication to start… >> %RCopyLOG% timeout /t 10 /nobreak cli showrcopy groups %RCG_NAME% >> %RCopyLOG% echo -------------------------------------------------------------------------------------------------------- >> %RCopyLOG% :endhotbackup echo ----- Validate that the End Hot Backup Scheduled task on %SourceServerName% is in a "Ready" state ----- >> %RCopyLOG% echo %DATE% %Time% >> %RCopyLOG% schtasks /query /S %SourceServerName% /FO list /TN %EHB% >> %RCopyLOG% echo %DATE% %Time% - Launch the End Hot Backup Scheduled task on %SourceServerName% >> %RCopyLOG% schtasks /run /s %SourceServerName% /tn %EHB% > %SchTskEHBLOG% ::This section will check the log to ensure that the scheduled task was started, since errorlevels cannot be used and it does not pipe out failures to the log file this is checking for SUCCESS, if it is not then it will email the failure. FOR /F "tokens=*" %%A IN ('FINDSTR /N "SUCCESS" "%SchTskEHBLOG%"') DO ( GOTO :rcsyncstatus ) :end GOTO :EHBFailed echo -------------------------------------------------------------------------------------------------------- >> %RCopyLOG% :rcsyncstatus echo ----- Validate rcopygroup %RCG_NAME% has completed its sync ----- >> %RCopyLOG% echo %DATE% %Time% >> %RCopyLOG% timeout /t 30 /nobreak cli showrcopy groups %RCG_NAME% > %RCopyStatusLOG% FOR /F "tokens=*" %%A IN ('FINDSTR /N "Syncing" "%RCopyStatusLOG%"') DO ( GOTO :rcsyncstatus ) :end Echo %DATE% %Time% - rcopygroup %RCG_NAME% has completed its sync operation >> %RCopyLOG% cli showrcopy groups %RCG_NAME% >> %RCopyLOG% time /t >> %RCopyLOG% echo -------------------------------------------------------------------------------------------------------- >> %RCopyLOG% ::Send email :HBSuccess echo ----- Email log files ----- >> %RCopyLOG% echo %DATE% %Time% >> %RCopyLOG% powershell.exe -command " & {Send-MailMessage -SMTPServer %SMTP% -To %EmailTo% -From '%SSMC%' -Attachments '\\%SourceServerName%\d$\3parlogs\%SourceServerName%-EHB.txt','\\%SourceServerName%\d$\3parlogs\%SourceServerName%-SHB.txt','%RCopyLOG%' -Subject '%SourceServerName% SAN replication to CHI was successful' -Body 'Please review the Oracle backup logs at \\%SourceServerName%\d$\3parlogs and on %TPDSYSNAME% for details' -Priority Normal}" exit :SHBFailed echo ----- Failed to run scheduled task email ----- >> %RCopyLOG% echo %DATE% %Time% >> %RCopyLOG% powershell.exe -command " & {Send-MailMessage -SMTPServer %SMTP% -To %EmailTo% -From '%SSMC%' -Attachments '%RCopyLOG%' -Subject '%SourceServerName% Failed to launch %SHB% - SAN replication to CHI FAILED' -Body 'The %SHB% scheduled task failed to run. Possible reasons could be that the task is disabled or the account is either locked out or its password has been changed. Please review the Oracle backup logs at \\%SourceServerName%\d$\3parlogs and on %TPDSYSNAME% for details' -Priority High}" exit :EHBFailed echo ----- Failed to run scheduled task email ----- >> %RCopyLOG% echo %DATE% %Time% >> %RCopyLOG% powershell.exe -command " & {Send-MailMessage -SMTPServer %SMTP% -To %EmailTo% -From '%SSMC%' -Attachments '%RCopyLOG%' -Subject '%SourceServerName% Failed to launch %EHB% - Database is in backup mode' -Body 'The %EHB% scheduled task failed to run, replication to CHI is either still in process or has completed. Possible reasons for the failure could be that the task is disabled or the account is either locked out or its password has been changed and needs to be updated on %SourceServerName%. Please review the Oracle backup logs at \\%SourceServerName%\d$\3parlogs and on %TPDSYSNAME% for details' -Priority High}" exit