Rman Backup script on Windows

Hello,

Here’s a script I created recently to backup a database under Windows with RMAN.

Hope you enjoy it.

Pierre

The script takes 4 parameters:

  • Target Database Sid
  • Rman Database Sid
  • Rman Database Password
  • Level of Rman backup

—–  Begin Script —–

SET ORACLE_HOME=E:\ORACLEORA10G
SET ORACLE_SID=%1%
SET RMAN_DB=%2%
SET CATALOG_PASS=%3%
SET LEVELBCK=%4%
SET CATALOG_PASS=rman/%CATALOG_PASS%@%RMAN_DB%
SET RMAN_DEST=K:\SAUVEGARDESRMAN%ORACLE_SID%
SET LOG_DEST=K:\SAUVEGARDESLOGS
SET NLS_LANG=AMERICAN_AMERICA.UTF8
SET TMPDIR=E:\ORACLETEMPSCRIPTS

@echo on

cd %TMPDIR%

REM This bit generates the RMAN script to backup database,
REM archivelogs and control file and then crosscheck output.
echo run { > rman_%ORACLE_SID%.rcv
echo allocate channel d1 type disk; >> rman_%ORACLE_SID%.rcv
echo allocate channel d2 type disk; >> rman_%ORACLE_SID%.rcv
echo allocate channel d3 type disk; >> rman_%ORACLE_SID%.rcv
echo backup incremental level %LEVELBCK% format
‘%RMAN_DEST%DBF_%ORACLE_SID%_t%%t_s%%s_p%%p.db’
database;>>rman_%ORACLE_SID%.rcv
echo sql ‘alter system archive log current’; >>rman_%ORACLE_SID%.rcv
echo backup archivelog all format
‘%RMAN_DEST%ARC_%ORACLE_SID%_t%%t_s%%s_p%%p.arc’;>>rman_%ORACLE_SID%.rcv
echo backup current controlfile format
‘%RMAN_DEST%CTL_%ORACLE_SID%_t%%t_s%%s_p%%p.ctl’;>>rman_%ORACLE_SID%.rcv
echo release channel d1; >> rman_%ORACLE_SID%.rcv
echo release channel d2; >> rman_%ORACLE_SID%.rcv
echo release channel d3; >> rman_%ORACLE_SID%.rcv
echo } >> rman_%ORACLE_SID%.rcv
echo allocate channel for maintenance type disk; >> rman_%ORACLE_SID%.rcv
echo sql ‘alter system archive log current’; >> rman_%ORACLE_SID%.rcv
echo crosscheck backup; >> rman_%ORACLE_SID%.rcv
echo crosscheck backup of archivelog all; >> rman_%ORACLE_SID%.rcv
echo crosscheck backup of controlfile; >> rman_%ORACLE_SID%.rcv
echo release channel; >> rman_%ORACLE_SID%.rcv
echo exit >> rman_%ORACLE_SID%.rcv

REM This starts RMAN, executes the script created earlier, then exits and
tidies up.
cd %RMAN_DEST%
if %LEVELBCK%==1 goto INCR
if %LEVELBCK%==0 goto FULL

:FULL
del %RMAN_DEST%*.* /q
rman target / catalog=%CATALOG_PASS% cmdfile=%TMPDIR%rman_%ORACLE_SID%.rcv
msglog=%LOG_DEST%rman_%ORACLE_SID%.log
del %TMPDIR%rman_%ORACLE_SID%.rcv
goto END
:INCR
rman target / catalog=%CATALOG_PASS% cmdfile=%TMPDIR%rman_%ORACLE_SID%.rcv
msglog=%LOG_DEST%rman_%ORACLE_SID%.log
del %TMPDIR%rman_%ORACLE_SID%.rcv
:END

—- end script —-

Advertisements

8 thoughts on “Rman Backup script on Windows

    1. Well, in certain cases it is not possible to take a full backup every day. Therefore the script gives the choice of either doing a full or incremental backup. In order to properly manage your backups that some of the basics a dba need to acquire.
      P.

  1. Dear,

    May be my question are very basic, sorry for that.

    You have specified the script, but it is very confusing to understand. Like where their is %1% , what are we supppose to put thier. From where the script is starting and ending it is not clear.

    please let me know more detail about it.

    1. Hello,
      I’ve updated the post to include script delimiters, you’ll see more easily where it begins and ends.
      As I specified, the script takes 4 parameters on the command line, they are %1%, %2%, …

      You would run the script like this: rman_backup.bat PRODDB RMANDB PASSRMAN 0

      P.

  2. Hello.
    Thanks for posting this script. It looks quite useful. One question: have you ever run into the problem that RMAN does not recognize a mapped network drive (on another Windows server of course) as a valid destination? Here is what I mean, take a look:

    — Create a file in the mapped network drive (Y:) that I want to use as my RMAN destination:
    C:>echo hello > Y:\ORACLE\BACKUPS\RMAN\SNIP3\test.txt

    — Check for the file just created in the mapped network drive Y:
    C:>dir Y:\ORACLE\BACKUPS\RMAN\SNIP3
    Volume in drive Y is Drobo
    Volume Serial Number is 144B-C2C3

    Directory of Y:\ORACLE\BACKUPS\RMAN\SNIP3

    03/11/2011 01:35 PM .
    03/11/2011 01:35 PM ..
    03/11/2011 01:35 PM 8 test.txt

    — File test.txt has been successfully created in the mapped network drive Y:

    — Here is a portion of the output of show all;
    RMAN> show all;

    RMAN configuration parameters are:
    CONFIGURE DEFAULT DEVICE TYPE TO DISK;
    CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘Y:/oracle/backups/RMAN/snip3/ctl_sp_bak_%F’;
    CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT ‘Y:/oracle/backups/RMAN/snip3/%U.bak’ MAXPIECESIZE 1 G;

    — Here are the error messages I get:
    RMAN> backup database;

    Starting backup at 11-mar-2011
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: sid=72 devtype=DISK
    channel ORA_DISK_1: starting full datafile backupset
    channel ORA_DISK_1: specifying datafile(s) in backupset
    input datafile fno=00003 name=E:\ORACLE\ORADATA\SNIP3\SYSAUX01.DBF
    input datafile fno=00001 name=E:\ORACLE\ORADATA\SNIP3\SYSTEM01.DBF
    input datafile fno=00002 name=E:\ORACLE\ORADATA\SNIP3\UNDOTBS01.DBF
    input datafile fno=00010 name=E:\ORACLE\ORADATA\SNIP3\EISAUX_DATA01.DBF
    input datafile fno=00005 name=E:\ORACLE\ORADATA\SNIP3\EISD01.DBF
    input datafile fno=00006 name=E:\ORACLE\ORADATA\SNIP3\EISX01.DBF
    input datafile fno=00012 name=E:\ORACLE\ORADATA\SNIP3\TOOLS01.DBF
    input datafile fno=00007 name=E:\ORACLE\ORADATA\SNIP3\EISLOB1.DBF
    input datafile fno=00004 name=E:\ORACLE\ORADATA\SNIP3\USERS01.DBF
    input datafile fno=00011 name=E:\ORACLE\ORADATA\SNIP3\EISAUX_IDX01.DBF
    input datafile fno=00008 name=E:\ORACLE\ORADATA\SNIP3\EISCTXD1.DBF
    input datafile fno=00009 name=E:\ORACLE\ORADATA\SNIP3\EISCTXX1.DBF
    input datafile fno=00017 name=E:\ORACLE\ORADATA\SNIP3\PTCDCTXD1.DBF
    input datafile fno=00018 name=E:\ORACLE\ORADATA\SNIP3\PTCDCTXX1.DBF
    input datafile fno=00013 name=E:\ORACLE\ORADATA\SNIP3\HTMLDB01.DBF
    input datafile fno=00016 name=E:\ORACLE\ORADATA\SNIP3\SMED01.DBF
    channel ORA_DISK_1: starting piece 1 at 11-mar-2011
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03009: failure of backup command on ORA_DISK_1 channel at 03/11/2011 12:50:25
    ORA-19504: failed to create file “Y:\ORACLE\BACKUPS\RMAN\SNIP3\Q4M6V0KF_1_1.BAK”
    ORA-27040: file create error, unable to create file
    OSD-04002: unable to open file
    O/S-Error: (OS 3) The system cannot find the path specified.

    Any ideas on what I need to do on my current server so that RMAN recognizes the mapped network drive Y: as a valid destination?

    Thanks in advance.
    JAC

  3. Thank you so much! That’s exactly the document I was looking for. I tried using the absolute path to the RMAN destination in the form of \\servername\e$\backups\… and it works.

    Thanks again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s