使用Pipe來執行RMAN命令
RMAN Pipe介面是執行RMAN命令並接收命令輸出的一種替代方法。使用這種介面,RMAN使用dbms_pipe包來獲得命令併傳送輸出來代替作業系統shell。使用這種介面,可以編寫可移值的RMAN程式介面。
pipe介面是透過使用pipe命令列引數來進行呼叫的。RMAN使用兩種私有管道:一個用來接收命令,一個用來傳送輸出。管道名是用pipe引數來決定的。例如,執行下面的命令 :
[oracle11@jingyong1 ~]$ rman PIPE abc TARGET / Recovery Manager: Release 11.2.0.4.0 - Production on Fri Apr 17 10:38:53 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
透過管道連線執行多個RMAN命令
假設想要透過管道來連續執行多個命令。在每一個命令傳送到管道執行並返回輸出後,RMAN會暫停並等待下一個命令。
1.以pipe選項來啟動RMAN並連線到目標資料庫:
[oracle11@jingyong1 ~]$ rman PIPE abc TARGET / Recovery Manager: Release 11.2.0.4.0 - Production on Fri Apr 17 10:38:53 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
也可以指定timeout選項,強制RMAN在指定的時間內沒有從輸入管道接收到命令就自動退出。
[oracle11@oracle11g ~]$ rman PIPE abc TARGET / TIMEOUT 60 Recovery Manager: Release 11.2.0.4.0 - Production on Fri Apr 17 14:51:12 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. [oracle11@oracle11g ~]$ date Fri Apr 17 14:52:14 CST 2015
2.連線管目標資料庫並透過dbms_pipe.pack_message與dbms_pipe.send_message在輸入管道中輸入要執行的命令。當RMAN使用管道來代替標準RMAN輸入時會顯示訊息RMAN-00572,下面使用管道來顯示當前的RMAN配置資訊並對資料庫執行備份。
[oracle11@oracle11g ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Fri Apr 17 11:49:25 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> set serverout on size 100000 SQL> declare 2 i_v varchar2(2000):='show all;'; 3 o_v number; 4 begin 5 dbms_pipe.pack_message(i_v); 6 o_v:=dbms_pipe.send_message('ORA$RMAN_ABC_IN'); 7 dbms_output.put_line(o_v); 8 commit; 9 end; 10 / 0 PL/SQL procedure successfully completed. [oracle11@oracle11g ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Fri Apr 17 11:49:30 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> set serverout on size 100000 SQL> declare 2 i_v varchar2(2000):='backup as backupset database plus archivelog;'; 3 o_v number; 4 begin 5 dbms_pipe.pack_message(i_v); 6 o_v:=dbms_pipe.send_message('ORA$RMAN_ABC_IN'); 7 dbms_output.put_line(o_v); 8 commit; 9 end; 10 / 0 PL/SQL procedure successfully completed.
3.使用dbms_pipe.receive_message和dbms_pipe.unpack_message來讀取RMAN的輸出資訊:
SQL> declare 2 output_v varchar2(4000); 3 o_v number:=0; 4 begin 5 while(o_v=0) loop 6 o_v:=dbms_pipe.receive_message('ORA$RMAN_ABC_OUT',5); 7 if o_v=0 then 8 dbms_pipe.unpack_message(output_v); 9 dbms_output.put_line(output_v); 10 end if; 11 end loop; 12 commit; 13 end; 14 / connected to target database: DB (DBID=1640573015) RMAN-00572: waiting for DBMS_PIPE input using target database control file instead of recovery catalog RMAN configuration parameters for database with db_unique_name DB are: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default CONFIGURE BACKUP OPTIMIZATION OFF; # default CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default CONFIGURE MAXSETSIZE TO UNLIMITED; # default CONFIGURE ENCRYPTION FOR DATABASE OFF; # default CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u03/app/oracle/11.2.0/db/dbs/snapcf_db.f'; # default RMAN-00572: waiting for DBMS_PIPE input PL/SQL procedure successfully completed. SQL> declare 2 output_v varchar2(4000); 3 o_v number:=0; 4 begin 5 while(o_v=0) loop 6 o_v:=dbms_pipe.receive_message('ORA$RMAN_ABC_OUT',600); 7 if o_v=0 then 8 dbms_pipe.unpack_message(output_v); 9 dbms_output.put_line(output_v); 10 end if; 11 end loop; 12 commit; 13 end; 14 / Starting backup at 2015-04-17 12:21:43 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=18 RECID=11 STAMP=877175019 input archived log thread=1 sequence=19 RECID=12 STAMP=877175163 input archived log thread=1 sequence=20 RECID=13 STAMP=877212065 input archived log thread=1 sequence=21 RECID=14 STAMP=877253311 input archived log thread=1 sequence=22 RECID=15 STAMP=877262007 input archived log thread=1 sequence=23 RECID=16 STAMP=877262176 input archived log thread=1 sequence=24 RECID=17 STAMP=877262429 input archived log thread=1 sequence=25 RECID=18 STAMP=877262605 input archived log thread=1 sequence=26 RECID=19 STAMP=877262607 input archived log thread=1 sequence=27 RECID=20 STAMP=877262777 input archived log thread=1 sequence=28 RECID=21 STAMP=877263703 channel ORA_DISK_1: starting piece 1 at 2015-04-17 12:21:44 channel ORA_DISK_1: finished piece 1 at 2015-04-17 12:21:59 piece handle=/u03/app/oracle/11.2.0/db/dbs/1fq4juqn_1_1 tag=TAG20150417T122143 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 Finished backup at 2015-04-17 12:21:59 Starting backup at 2015-04-17 12:21:59 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/u03/app/oracle/oradata/db/system01.dbf input datafile file number=00002 name=/u03/app/oracle/oradata/db/sysaux01.dbf input datafile file number=00005 name=/u03/app/oracle/oradata/db/example01.dbf input datafile file number=00003 name=/u03/app/oracle/oradata/db/undotbs01.dbf input datafile file number=00004 name=/u03/app/oracle/oradata/db/users01.dbf channel ORA_DISK_1: starting piece 1 at 2015-04-17 12:21:59 channel ORA_DISK_1: finished piece 1 at 2015-04-17 12:24:34 piece handle=/u03/app/oracle/11.2.0/db/dbs/1gq4jur7_1_1 tag=TAG20150417T122159 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:02:36 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 2015-04-17 12:24:42 channel ORA_DISK_1: finished piece 1 at 2015-04-17 12:24:43 piece handle=/u03/app/oracle/11.2.0/db/dbs/1hq4jv03_1_1 tag=TAG20150417T122159 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 2015-04-17 12:24:43 Starting backup at 2015-04-17 12:24:43 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=29 RECID=22 STAMP=877263883 channel ORA_DISK_1: starting piece 1 at 2015-04-17 12:24:44 channel ORA_DISK_1: finished piece 1 at 2015-04-17 12:24:45 piece handle=/u03/app/oracle/11.2.0/db/dbs/1iq4jv0c_1_1 tag=TAG20150417T122444 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 2015-04-17 12:24:45 RMAN-00572: waiting for DBMS_PIPE input Starting backup at 2015-04-17 12:26:09 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=18 RECID=11 STAMP=877175019 input archived log thread=1 sequence=19 RECID=12 STAMP=877175163 input archived log thread=1 sequence=20 RECID=13 STAMP=877212065 input archived log thread=1 sequence=21 RECID=14 STAMP=877253311 input archived log thread=1 sequence=22 RECID=15 STAMP=877262007 input archived log thread=1 sequence=23 RECID=16 STAMP=877262176 input archived log thread=1 sequence=24 RECID=17 STAMP=877262429 input archived log thread=1 sequence=25 RECID=18 STAMP=877262605 input archived log thread=1 sequence=26 RECID=19 STAMP=877262607 input archived log thread=1 sequence=27 RECID=20 STAMP=877262777 input archived log thread=1 sequence=28 RECID=21 STAMP=877263703 input archived log thread=1 sequence=29 RECID=22 STAMP=877263883 input archived log thread=1 sequence=30 RECID=23 STAMP=877263969 channel ORA_DISK_1: starting piece 1 at 2015-04-17 12:26:10 channel ORA_DISK_1: finished piece 1 at 2015-04-17 12:26:25 piece handle=/u03/app/oracle/11.2.0/db/dbs/1jq4jv32_1_1 tag=TAG20150417T122610 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 Finished backup at 2015-04-17 12:26:25 Starting backup at 2015-04-17 12:26:25 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00001 name=/u03/app/oracle/oradata/db/system01.dbf input datafile file number=00002 name=/u03/app/oracle/oradata/db/sysaux01.dbf input datafile file number=00005 name=/u03/app/oracle/oradata/db/example01.dbf input datafile file number=00003 name=/u03/app/oracle/oradata/db/undotbs01.dbf input datafile file number=00004 name=/u03/app/oracle/oradata/db/users01.dbf channel ORA_DISK_1: starting piece 1 at 2015-04-17 12:26:26 channel ORA_DISK_1: finished piece 1 at 2015-04-17 12:29:21 piece handle=/u03/app/oracle/11.2.0/db/dbs/1kq4jv3i_1_1 tag=TAG20150417T122625 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:02:55 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 2015-04-17 12:29:24 channel ORA_DISK_1: finished piece 1 at 2015-04-17 12:29:27 piece handle=/u03/app/oracle/11.2.0/db/dbs/1lq4jv91_1_1 tag=TAG20150417T122625 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 Finished backup at 2015-04-17 12:29:27 Starting backup at 2015-04-17 12:29:27 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=31 RECID=24 STAMP=877264168 channel ORA_DISK_1: starting piece 1 at 2015-04-17 12:29:28 channel ORA_DISK_1: finished piece 1 at 2015-04-17 12:29:29 piece handle=/u03/app/oracle/11.2.0/db/dbs/1mq4jv98_1_1 tag=TAG20150417T122928 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 2015-04-17 12:29:29 RMAN-00572: waiting for DBMS_PIPE input PL/SQL procedure successfully completed.
4.如果啟動RMAN時使用了timeout選項,那麼RMAN在指定時間間隔內沒有接收到任何命令就會自動終止RMAN會話。為了強制RMAN立即終止RMAN會話可以傳送exit命令。
SQL> declare 2 i_v varchar2(2000):='exit;'; 3 o_v number; 4 begin 5 dbms_pipe.pack_message(i_v); 6 o_v:=dbms_pipe.send_message('ORA$RMAN_ABC_IN'); 7 dbms_output.put_line(o_v); 8 commit; 9 end; 10 / PL/SQL procedure successfully completed. SQL> declare 2 output_v varchar2(4000); 3 o_v number:=0; 4 begin 5 while(o_v=0) loop 6 o_v:=dbms_pipe.receive_message('ORA$RMAN_ABC_OUT',10);--10是超過時間為10秒 7 if o_v=0 then 8 dbms_pipe.unpack_message(output_v); 9 dbms_output.put_line(output_v); 10 end if; 11 end loop; 12 commit; 13 end; 14 / Recovery Manager complete. PL/SQL procedure successfully completed.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-1583347/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用RMAN來PDB執行完全恢復
- RMAN的PIPE介面
- RMAN的PIPE介面(二)
- 使用RMAN執行維護操作——RMAN使用者手冊
- sqlplus & rman 命令下,使用上下翻動鍵,呼叫之前執行過的命令SQL
- oracle實驗-RMAN的PIPE介面Oracle
- 用 PHP 來執行執行網路相關命令PHP
- 使用NetCat或BASH建立反向Shell來執行遠端執行Root命令
- 【機器學習】使用Octave執行命令機器學習
- 通過API執行AutoCAD命令來…API
- 使用RMAN執行oracle ASM資料遷移OracleASM
- Golang 使用執行命令帶管道符執行的方法Golang
- 用RMAN執行DUPLICATE資料庫操作——RMAN使用者手冊資料庫
- Oracle ASM使用asmcmd中的cp命令來執行遠端複製OracleASM
- python基礎之使用os.system來執行系統命令Python
- 使用RMAN對CDB的root執行完全恢復
- 以root使用者執行命令
- pipe函式使用函式
- 使用RMAN DUPLICATE...FROM ACTIVE DATABASE命令來建立DataGuard物理備庫Database
- 使用RMAN對PDB執行按時間點恢復
- 使用RMAN對CDB執行按時間點恢復
- 使用RMAN對PDB執行閃回資料庫操作資料庫
- 使用RMAN對CDB執行閃回資料庫操作資料庫
- Linux使用time命令獲取命令執行時間Linux
- 使用 DBMS_SCHEDULER執行外部命令
- [linux] 使用Screen後臺執行命令Linux
- RMAN恢復 執行重要檔案RMAN恢復
- RMAN自動執行計劃
- 用rman執行塊恢復
- 用RMAN執行表空間及時點恢復——RMAN使用者手冊
- 命令執行漏洞
- Docker執行命令Docker
- 寫一段java程式來執行linux命令JavaLinux
- OCP課程48:管理II之使用RMAN執行恢復
- 使用 sail 執行 artisan 等命令無響應AI
- rman 命令
- RMAN命令
- 使用rman執行recover database 的時候出現RMAN-06054的錯誤提示Database