@ECHO OFF :: file : backup.cmd :: description : run rman backup to disk :: :: Author: Christof Prettner :: Version: 0.1 :: History :: Version + Date + Author + Updates :: ——————————————————— :: 0.1 | 28.03.2017| Christof Prettner | Initial :: 0.2 | 28.03.2017| Christof Prettner | Set Date Time properly, added rundatetime into CMDFILE :: First: date and time setting (RUNDATETIME) :: :: :: According to your local Server please change the following parameters before first execution. :: RUNDIR - the location where the RMAN command file will be stored :: LOGDIR - the location where to store the logfiles of the Database Backup :: ORACLE_HOME - the Location of the Oracle Binaries :: ORACLE_BASE - the root Directory of the Oracle Installation :: BACKUPDIR - the location where snapshotcontrolfile, controlfileautobackups and the backup controlfile to trace will be stored set arg1=%1 for /F %%a in (' wmic os get LocalDateTime^| findstr ^[0-9]') do (set datetime=%%a) set RUNDATETIME=%datetime:~0,8%-%datetime:~8,4% :: :: Configuration :: (you may simply replace this with parameters of course) :: set ORACLE_SID=%arg1% :: rundir==> where the rman-commandfile will be build and run. :: you must have write-permission to that directory! set RUNDIR=D:\ORACLE\scripts set LOGDIR=D:\ORACLE\scripts\log set ORACLE_HOME=D:\app\oracle\product\12.2.0.1\db1 set ORACLE_BASE=D:\app\oracle set PATH=%ORACLE_HOME%\bin;%PATH% set NLS_DATE_FORMAT="DD-MM-YY HH24:MI:SS" set BACKUPDIR=D:\Oracle\backup set LOGFILE=%LOGDIR%\%ORACLE_SID%_%RUNDATETIME%.log set ADDR=’job@jobacle.at’ set TMPLOG=%LOGDIR%\tmplog.$$ :: :: Cleaning up of old logfiles will be done in another program :: :: Build de rman-commandfile set CMDFILE=%RUNDIR%\%ORACLE_SID%_%RUNDATETIME%.rman echo run { > %CMDFILE% echo CONFIGURE RETENTION POLICY TO REDUNDANCY 2; >> %CMDFILE% echo CONFIGURE BACKUP OPTIMIZATION ON; >> %CMDFILE% echo CONFIGURE DEFAULT DEVICE TYPE TO DISK; >> %CMDFILE% echo CONFIGURE CONTROLFILE AUTOBACKUP ON; >> %CMDFILE% echo CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%BACKUPDIR%\ora_cf%%F'; >> %CMDFILE% echo CONFIGURE DEVICE TYPE DISK PARALLELISM 2; >> %CMDFILE% echo CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; >> %CMDFILE% echo CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; >> %CMDFILE% echo CONFIGURE MAXSETSIZE TO UNLIMITED; >> %CMDFILE% echo CONFIGURE SNAPSHOT CONTROLFILE NAME TO '%BACKUPDIR%\snapcf_%ORACLE_SID%_%RUNDATETIME%.f'; >> %CMDFILE% :: explicitly names the format in the allocate channel echo SHOW ALL; >> %CMDFILE% echo sql "alter system archive log current"; >> %CMDFILE% echo DELETE FORCE NOPROMPT ARCHIVELOG ALL COMPLETED BEFORE 'sysdate-1'; >> %CMDFILE% echo BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL=0 DATABASE INCLUDE CURRENT CONTROLFILE PLUS ARCHIVELOG; >> %CMDFILE% :: echo sql "alter database backup controlfile to trace as "%BACKUPDIR%\ctrlfile_%ORACLE_SID%_%RUNDATETIME%""; >> %CMDFILE% echo CROSSCHECK BACKUP; >> %CMDFILE% echo REPORT OBSOLETE; >> %CMDFILE% echo DELETE FORCE NOPROMPT OBSOLETE; >> %CMDFILE% :: :: RMAN don’t like the following in the run-command apparently… :: :: echo LIST BACKUP OF DATABASE; >> %CMDFILE% :: echo LIST BACKUP OF ARCHIVELOG ALL; >> %CMDFILE% :: echo LIST BACKUP; >> %CMDFILE% echo } >> %CMDFILE% :: End of Command File Generation echo Starting the script > %LOGFILE% %ORACLE_HOME%\bin\rman target / cmdfile=%CMDFILE% msglog=%TMPLOG% >>%LOGFILE% :: :: merge the two logfiles type %TMPLOG% >> %LOGFILE% echo Starting backup controlfile to trace > %LOGFILE% echo alter database backup controlfile to trace as 'D:\oracle\backup\controlbackup_%RUNDATETIME%.bkp'; | sqlplus / as sysdba >> %LOGFILE% :: :: checking for errors :: ::findstr /i "RMAN-06273" %LOG% >> %LOGFILE%