分离job必须指向一个程序对象,程序对象的分离属性设置为true。下面的盒子是在Linux和系统上创建一个夜间job来对数据库执行备份。
1.创建一个脚本来调用RMAN备份脚本,脚本名为$ORACLE_HOME/scripts/backup.sh
[oracle@sjjh scripts]$ vi backup.sh export ORACLE_HOME=/home/app/oracle/product/11.2.0 export ORACLE_SID=sjjh export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib $ORACLE_HOME/bin/rman TARGET / @$ORACLE_HOME/scripts/backup.rman trace /home/app/oracle/backup/backup.out & exit 0
2.创建rman备份脚本,脚本名为$ORACLE_HOME/scripts/backup.rman
[oracle@sjjh scripts]$ vi backup.rman run{ # Perform full database backup backup full format "/home/app/oracle/backup/%d_FULL_%U" (database) ; # Open database after backup alter database open; # Call notification routine to indicate job completed successfully sql " BEGIN DBMS_SCHEDULER.END_DETACHED_JOB_RUN(''sys.backup_job'', 0, null); END; "; }
3.创建job并使用分离程序对象
[oracle@sjjh scripts]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Thu Jul 13 11:13:44 2017 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> BEGIN 2 DBMS_SCHEDULER.CREATE_PROGRAM( 3 program_name => 'sys.backup_program', 4 program_type => 'executable', 5 program_action => '/home/app/oracle/product/11.2.0/scripts/coldbackup.sh', 6 enabled => TRUE); 7 8 DBMS_SCHEDULER.SET_ATTRIBUTE('sys.backup_program', 'detached', TRUE); 9 DBMS_SCHEDULER.CREATE_JOB( 10 job_name => 'sys.backup_job', 11 program_name => 'sys.backup_program', 12 repeat_interval => 'FREQ=DAILY;BYHOUR=1;BYMINUTE=0'); 13 14 DBMS_SCHEDULER.ENABLE('sys.backup_job'); 15 END; 16 / PL/SQL procedure successfully completed.