Control RMAN using PIPE

Hi,

today i`ve got a quick and easy article about controling RMAN with PIPE.

Some of you may remamber the package DBMS_PIPE, its a package that help us send and recieve messages from public and private pipe, we can use it to control RMAN from PL/SQL.

First we have to run rman in mode which create pipes,

rman target / PIPE '"<pipe_name>"' log rman_pipe.log

PIPE – tell rman to open named pipe
log – tell rman to log output to rman_pipe.log it`s not nessesary but can be helpfull in diagnosing what`s going on

After runing this command nothing is seen on the screen, we can check if Oracle create PIPES using:
SELECT name, type pipe_size FROM v$db_pipes
we shout seen at least two pipes with names: ORA$RMAN__(OUT|IN).
As you figure out OUT pipe is to get information from RMAN, IN is to pass information to RMAN.

Ok, sofar we`ve got running RMAN command and veryfy that our PIPES are created, let`s write and read sth from them.

PL/SQL PIPE maintain
To write to the PIPE U can use this code:

DECLARE
v_status INTEGER;
BEGIN
dbms_pipe.pack_message('report schema;');
v_status := dbms_pipe.send_message('PIPE_NAME_IN');
IF v_status !=0 THEN
RAISE_APPLICATION_ERROR(-20666,'ERROR DURING WRITING TO RMAN');
END IF;
END;
/

status code different than 0 is error. Check if your pipe realy exists, and that you run this code from SYSDATE , because it`s private pipe.

To read from it use this code:

DECLARE
v_message VARCHAR2(32000);
v_status INTEGER;
BEGIN
LOOP
v_status := dbms_pipe.receive_message('ORA$RMAN_P1_OUT');
IF v_status = 0 THEN
DBMS_OUTPUT.PUT_LINE('MAM');
dbms_pipe.unpack_message(v_message);
DBMS_OUTPUT.PUT_LINE(v_message);
END IF;
EXIT WHEN v_status !=0 OR REGEXP_LIKE(v_message,'RMAN-00572') ;
END LOOP;
END;
/

It`ll read all messages from RMAN until end of message is shown (RMAN-00572) or status different from 0, which mean error.

That`s all, oportunity are endless, you can control your list your backups, made them, modify your backup settings according of what is beeing return to you by RMAN.

Leave a comment