DOYENSYS Knowledge Portal




We Welcome you to visit our DOYENSYS KNOWLEDGE PORTAL : Doyensys Knowledge Portal




Thursday, September 10, 2015

Windows Server R2 Batch Script for RMAN compressed backup
--------------------------------------------------------------------------------

The below script will run the RMAN backup in a compressed format and it will trigger the status of the backup to mail.

Batch file : 
--------------
1) Save the file like RMAN_BKP.bat.
2) Edit the values of TO, SERVER, FROM & ORACLE_SID as per the environment.
3) Save the Command file as name in the script (rmandb_bk_new.txt)


RMAN_BKP.bat
-------------------

set TO=support@xxx.com
set SERVER=mailserver:port
set FROM=supportmail@xxx.com
SET ORACLE_SID=PROD
rman cmdfile=E:\monitoring_scripts\rmandb_bk_new.txt > E:\monitoring_scripts\log\rman_backup.log
findstr /R /N "ORA-"  E:\monitoring_scripts\log\rman_backup.log | find /C ":" > E:\monitoring_scripts\log\rman_test_count.txt
set /p ABC=<E:\monitoring_scripts\log\rman_test_count.txt
@ECHO OFF
Set dir=E:\PROD\ARCHIVELOGS
Echo Deleting all files from %dir%
del %dir%\* /F /Q 
@echo Folder deleted.
SETLOCAL enableextensions
(for /f "tokens=1-3" %%a in ('
  WMIC LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"
  ') do (
    echo wsh.echo "%%b" ^& " free=" ^& FormatNumber^(cdbl^(%%a^)/1024/1024/1024, 2^)^& " GB"^& " size=" ^& FormatNumber^(cdbl^(%%c^)/1024/1024/1024, 2^)^& " GB" > "%temp%\tmp.vbs"
    if not "%%c"=="" (
      echo( 
      cscript //nologo "%temp%\tmp.vbs"
      del "%temp%\tmp.vbs"
    )
  )
) >E:\monitoring_scripts\Disk_status.txt
type E:\monitoring_scripts\log\status.txt E:\monitoring_scripts\Disk_status.txt > E:\monitoring_scripts\log\rman_success.txt
type E:\monitoring_scripts\log\Rman_status.txt E:\monitoring_scripts\Disk_status.txt > E:\monitoring_scripts\log\rman_failed.txt
if %ABC% GEQ 1 ( blat E:\monitoring_scripts\log\rman_failed.txt -server %SERVER% -f %FROM% -to %TO% -subject "CRITICAL : Rman Backup Failed") else ( blat E:\monitoring_scripts\log\rman_success.txt  -server %SERVER% -f %FROM% -to %TO% -subject "Rman Backup Completed Successfuly")

del E:\monitoring_scripts\log\rman_test_count.txt
del E:\monitoring_scripts\log\rman_success.txt
del E:\monitoring_scripts\log\rman_failed.txt



Command File :
--------------------

Description :
----------------
1) The below script will run rman compressed backup of full database and the redundancy is 2. After the backup, it will delete the previous day's archive log and also the old backup peices
2) Save the below file as rmandb_bk_new.txt


rmandb_bk_new.txt  : 
----------------------------
connect target sys/sys
configure controlfile autobackup on;
configure backup optimization on;
configure controlfile autobackup format for device type disk to 'E:\rman_backup\%d_%F.bkp';
configure retention policy to redundancy 2;
run
{
allocate channel c1 type disk format 'E:\rman_backup\C1_%d_%s_%p_%c.bkp';
allocate channel c2 type disk format 'E:\rman_backup\C2_%d_%s_%p_%c.bkp';
allocate channel c3 type disk format 'E:\rman_backup\C3_%d_%s_%p_%c.bkp';
backup as compressed backupset filesperset 3 database tag='FULL_DB_BKP';
backup current controlfile format 'E:\rman_backup\Cntrl_%d_%s_%p_%D_%M_%Y';
crosscheck archivelog all;
backup as compressed backupset archivelog all format 'E:\rman_backup\archive_log_bkp\Compressed_%d_%s_%p_%c.bkp' tag='FULL_ARCH_BKP';
delete noprompt archivelog until time 'SYSDATE-1'; 
release channel c1;
release channel c2;
release channel c3;
}
crosscheck backupset of database;
crosscheck backupset of controlfile;
crosscheck backupset of archivelog all;
delete noprompt obsolete;

No comments: