Skip to main content
Druva Documentation

Template batch file and RMAN script for Windows RMAN hosts

Phoenix Editions: File:/tick.png Business File:/cross.png Enterprise File:/tick.png Elite

Druva provides a template batch file and an RMAN script for Windows RMAN hosts that you can use to backup databases. The scripts are:

  • oracle_rman_backup.bat: This batch file runs the RMAN script that backs up a database. You can modify this script to provide RMAN parameters that specify the type of backup and information related to backup like filesperset and channels for a backup. 
  • rman_backup_windows.rman: This script runs the backup job on RMAN.

The following sections provide the contents of the batch file and the RMAN script. You can edit these scripts to suit your requirements.

oracle_rman_backup.bat

echo off

if not "%~3"=="" if "%~4"=="" goto START
echo This script requires the next parameters:
echo - log_file_directory backup_store_ip mount_name
echo - log_file_directory : Directory for RMAN log file
echo - backup_store_ip : IP of backup store
echo - mount_name : backup mount name as in CPortal
goto EOF

:START

setlocal enableDelayedExpansion enableextensions

if not exist %1 (
    mkdir %1
    if !ERRORLEVEL! NEQ 0 (
        echo Unable to create directory %1.. exiting
        exit /b
        )
    )

for /F "tokens=*" %%I in ('curl -X GET http://%2:9090/druva-phoenix/v1/mounts/%3/backup') do set validate_curl_output=%%I
set VALIDATE_JSON=%validate_curl_output%

set "VALIDATE_JSON=%VALIDATE_JSON:~1,-1%"
set "VALIDATE_JSON=%VALIDATE_JSON:":=",%"

set /a vcount = 0

REM Check for validate response
for %%I in (%VALIDATE_JSON%) do (
    if !vcount! == 1 ( 
        if /I NOT %%I == 0 (
            echo Request to validate backup failed, exiting
            echo Response from Phoenix Backup Store %VALIDATE_JSON%
            exit /b 1
        ) else (
            echo Request to validate backup succeeded
        )
    )

    REM is_max_snapshot_reached
    if !vcount! == 6 (
        if %%~I == "true" (
            echo Request to validate backup failed, exiting
            echo Response from Phoenix Backup Store %VALIDATE_JSON%
            exit /b 1
        )
    )

    set /a "vcount+=1"
)

for /F %%I in ('curl -X POST http://%2:9090/druva-phoenix/v1/mounts/%3/backup') do set curl_output=%%I

set JSON=%curl_output%

set "JSON=%JSON:~1,-1%"
set "JSON=%JSON:":=",%"

set /a count = 0

for %%I in (%JSON%) do (
    if !count! == 1 ( 
        if /I NOT %%I == 0 (
            echo Request to start backup failed, exiting
            echo Response from Phoenix Backup Store %JSON%
            exit /b 1
        ) else (
            echo Request to start backup succeeded
        )
    )

    if !count! == 6 (
        set mount_name=%%~I
    )

    if !count! == 13 (
        set mount_path=%%~I
    )

    set /a "count+=1"
)

set mount_path=%mount_path:~,-2%
set mount_path=!mount_path:/=\!
set complete_mount=\\%2%mount_path%
echo Mount name %mount_name%
echo NFS mount path %complete_mount%

if not exist %complete_mount%\full (
    echo Creating directory %complete_mount%\full
    mkdir %complete_mount%\full
    if !ERRORLEVEL! NEQ 0 (
        echo Unable to create directory %complete_mount%\full.. exiting
        exit /b
        )
    )

FOR /F "tokens=*" %%a in ('date /t') do SET date=%%a
set date=!date: =_!
set date=!date:/=_!

FOR /F "tokens=*" %%a in ('time /t') do SET time=%%a
set time=!time: =_!
set time=!time::=_!

rman log=%1\rman_full_backup.log @rman_backup_windows.rman using '%complete_mount%'
if !ERRORLEVEL! NEQ 0 (
    move %1\rman_full_backup.log %1\rman_full_backup%date%%time%.log
    echo RMAN backup failed. Check RMAN log %1\rman_full_backup%date%%time%.log for the details
    exit /b
    )

move %1\rman_full_backup.log %1\rman_full_backup%date%%time%.log
echo RMAN backup completed
echo RMAN log file %1\rman_full_backup%date%%time%.log


echo Notifying Phoenix to upload RMAN Logs
for /F %%I in ('curl -X POST -H "Content-Type: multipart/form-data" -F "file=@%1\rman_full_backup%date%%time%.log" -F "mountpoint=%complete_mount%" -F "platform=windows" http://%2:9090/druva-phoenix/v1/mounts/%3/uploadlog') do set rman_upload_log_curl_output=%%I

echo Response from Phoenix Backup Store for upload RMAN Log: %rman_upload_log_curl_output%


for /F %%I in ('curl -X PUT http://%2:9090/druva-phoenix/v1/mounts/%3/backup') do set curl_output2=%%I

echo Response from Phoenix Backup Store : %curl_output2%

:EOF
exit /b

rman_backup_windows.rman

connect target /
set echo on;

configure backup optimization on;
configure controlfile autobackup on;
configure device type disk parallelism 1 BACKUP TYPE TO COPY;
configure datafile backup copies for device type disk to 1;
configure archivelog backup copies for device type disk to 1;
configure channel device type disk format '&1\full\full_bk_datafile_%U.rbk';
configure controlfile autobackup format for device type disk to '&1\full\full_bk_controlfile_%F';

run
{

backup incremental level 1 for recover of copy with tag 'phoenix_oracle_backup' database;
backup format '&1\full\full_bk_Archivelog_%d_%s_%t' archivelog all not backed up;
recover copy of database with tag 'phoenix_oracle_backup';

#Force is to ignore I/O errors
delete noprompt obsolete device type disk;
delete force NOPROMPT expired copy;
delete force NOPROMPT expired backup;

crosscheck backup;
crosscheck copy;
}

configure backup optimization clear;
configure controlfile autobackup clear;

exit