echo off
rem *******************************
rem ***rm_archlog_crosscheck 1.0***
rem *******************************

rem ***Установка имени целевой БД***
Set _TargetName=MAGICASH

rem ***Установка SYS пароля целевой БД***
Set _SysPsw=NCTSYS

rem ***Установка папки резервного копирования***
Set _BackupDir=C:\oracle\backuprman\

rem ***Установка кол-ва сохраняемых копий (1 - только последняя копия)***
Set _red_int=2

rem ****************************
rem ****************************
rem ****************************
rem ****************************
rem ****************************
rem ****************************
rem ****************************

rem script name
Set _ScriptName=rm_archlog_crosscheck_%_TargetName%
rem operation name
Set _OperName=Crosscheck Archivelogs and Backups

Set _Date=%date%
If "%_Date%A" LSS "A" (Set _NumTok=1-3) Else (Set _NumTok=2-4)
:: Default Delimiter of TAB and Space are used
For /F "TOKENS=2*" %%A In ('REG QUERY "HKCU\Control Panel\International" /v iDate') Do Set _iDate=%%B
For /F "TOKENS=2*" %%A In ('REG QUERY "HKCU\Control Panel\International" /v sDate') Do Set _sDate=%%B
IF %_iDate%==0 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%D%%B%%C
IF %_iDate%==1 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%D%%C%%B
IF %_iDate%==2 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%_Date%") Do Set _fdate=%%B%%C%%D
Set _Today=%_fdate:~0,4%%_fdate:~4,2%%_fdate:~6,2%


rem создание папки логов
md %_BackupDir%\logs_%_Today%
rem создание папки бекапов
md %_BackupDir%\backups_%_Today%
rem пересоздание файла скрипта
del %_ScriptName%.rcv
fsutil file createnew %_ScriptName%.rcv 0


rem задание команд RMAN
echo configure controlfile autobackup on; >> "%_ScriptName%.rcv"
echo ### Checking and Clearing Metadata >> "%_ScriptName%.rcv"
echo crosscheck backup; >> "%_ScriptName%.rcv"
echo delete expired backup; >> "%_ScriptName%.rcv"
echo crosscheck archivelog all; >> "%_ScriptName%.rcv"
echo delete expired archivelog all; >> "%_ScriptName%.rcv"
echo delete obsolete redundancy %_red_int%; >> "%_ScriptName%.rcv"
echo # >> "%_ScriptName%.rcv"
rem окончание задания команд RMAN


rem создание лога операции
echo ================== >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"
echo Запуск RMAN >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"
echo Операция - %_OperName% >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"
time/t >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"
date/t >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"
echo Строка подключения целевой БД - SYS/%_SysPsw%@%_TargetName% >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"
rem echo Строка подключения БД каталога - %_RecUser%/%_RecPsw%@%_RecName% >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"

rem строка запуска RMAN
rman log='%_BackupDir%\logs_%_Today%\%_ScriptName%_%_Today%.log' target sys/%_SysPsw%@%_TargetName% nocatalog @%_ScriptName%.rcv
 
 
rem завершение лога операции 
echo Окончание RMAN >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"
time/t >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"
date/t >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"
echo ================== >> "%_BackupDir%\logs_%_Today%\%_Today%__rman.log"

