Oracle: Scheduling Rman backup jobs through DBMS_SCHEDULER.
In this article we will learn how to schedule RMAN backup jobs through DBMS_SCHEDULER.
Before reading this article Please check previous article on DBMS_SCHEDULER.
Step 1 :
Create the Script That Invokes RMAN
Create a shell script that calls an RMAN script to perform a cold backup. The shell script is located in /u01/scripts/full_rmanbkp.sh. It must be executable by the user who installed Oracle Database (typically the user oracle
).
1 2 3 4 5 6 7 8 9 |
#!/bin/sh export ORACLE_HOME=/u01/app/oracle/product/12.1.0 export ORACLE_SID=primary export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib $ORACLE_HOME/bin/rman TARGET / /u01/scripts/full_rmanbkp.rman trace /u01/app/oracle/backup/full_rmanbkp.out & exit 0 |
Step 2 :
Create another script of RMAN.
Create an RMAN script that performs the cold backup and then ends the job. The script is located in /u01/scripts/full_rmanbkp.rman.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
run { # Shut down database for backups and put into MOUNT mode shutdown immediate startup mount # Perform full database backup backup database plus archivelog; # Open database after backup alter database open; # Call notification routine to indicate job completed successfully sql " BEGIN DBMS_SCHEDULER.END_DETACHED_JOB_RUN(''sys.full_rmanbkp'', 0, null); END; "; } |
Step 3 :
Create the Job and Use a Detached Program
Submit the following PL/SQL block on sqlplus prompt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
BEGIN DBMS_SCHEDULER.CREATE_PROGRAM( program_name => 'sys.full_rmanbkp_program', program_type => 'executable', program_action => '/u01/scripts/full_rmanbkp.sh', enabled => TRUE); DBMS_SCHEDULER.SET_ATTRIBUTE('sys.full_rmanbkp', 'detached', TRUE); DBMS_SCHEDULER.CREATE_JOB( job_name => 'sys.full_rmanbkp', program_name => 'sys.full_rmanbkp_program', repeat_interval => 'FREQ=daily;byhour=1;byminute=0;bysecond=0'); DBMS_SCHEDULER.ENABLE('sys.full_rmanbkp'); END; / |
Step 4:
Check the job details using views.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
SYS>> SELECT owner, job_name, enabled FROM dba_scheduler_jobs; OWNER Job-Name ENABL -------- ------------------------------ ----- SYS FULL_RMANBKP_ TRUE SYS LOAD_OPATCH_INVENTORY FALSE SYS SM$CLEAN_AUTO_SPLIT_MERGE TRUE SYS RSE$CLEAN_RECOVERABLE_SCRIPT TRUE SYS FGR$AUTOPURGE_JOB FALSE SYS BSLN_MAINTAIN_STATS_JOB TRUE SYS DRA_REEVALUATE_OPEN_FAILURES TRUE SYS HM_CREATE_OFFLINE_DICTIONARY FALSE SYS ORA$AUTOTASK_CLEAN TRUE SYS PURGE_LOG TRUE SYS FILE_SIZE_UPD TRUE SYS CLEANUP_ONLINE_PMO TRUE SYS CLEANUP_TRANSIENT_PKG TRUE SYS CLEANUP_TRANSIENT_TYPE TRUE SYS CLEANUP_TAB_IOT_PMO TRUE SYS CLEANUP_ONLINE_IND_BUILD TRUE SYS CLEANUP_NON_EXIST_OBJ TRUE SYS PMO_DEFERRED_GIDX_MAINT_JOB TRUE SYS FILE_WATCHER FALSE SYS XMLDB_NFS_CLEANUP_JOB FALSE 20 rows selected. |
Step 5 :
Check a particular job details.
1 2 3 4 5 |
SYS>> SELECT owner, job_name, enabled,NEXT_RUN_DATE,RAISE_EVENTS,LAST_START_DATE from dba_scheduler_jobs where JOB_NAME='FULL_RMANBKP'; OWNER Job-Name ENABL NEXT_RUN_DATE RAISE_EVENTS LAST_START_DATE -------- --------------- ----- ------------------------- --------------- ------------------------- SYS FULL_RMANBKP_ TRUE 27-FEB-19 01.00.00.505056 AM ASIA/CALCUTTA |
Yes , The Job was scheduled to 27th Feb at 1:00 AM. Just wait until the job executes.
Step 6 :
disagreement
Providing great service