/u01/app/oracle/rman_backup/backup.rmn
RUN { BACKUP SPFILE FORMAT '+FRA/racdb/backupset/spfile_%d_%s_%T' DATABASE INCLUDE CURRENT CONTROLFILE FORMAT '+FRA/racdb/backupset/data_%d_%s_%T' ARCHIVELOG ALL FORMAT '+FRA/racdb/backupset/arc_%d_%s_%T'; BACKUP DEVICE TYPE DISK FORMAT '/backup/data_%d_%s_%T_%U' BACKUPSET COMPLETED AFTER 'SYSDATE - 1/24'; CROSSCHECK BACKUP; CROSSCHECK BACKUPSET; CROSSCHECK ARCHIVELOG ALL; DELETE NOPROMPT EXPIRED ARCHIVELOG ALL; DELETE NOPROMPT EXPIRED BACKUP; DELETE NOPROMPT OBSOLETE; }
/u01/app/oracle/rman_backup/run_backup.sh #!/bin/bash /u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / cmdfile=$*
rman
utility should be fully specified. $ sqlplus / as sysdba SQL> create or replace directory bkp_dir as '/u01/app/oracle/rman_backup/';
$ sqlplus / as sysdba SQL> create user bkp identified by rmanbkp; SQL> grant connect to bkp; SQL> grant create table to bkp; SQL> grant create procedure to bkp; SQL> grant create type to bkp; SQL> grant create job to bkp; SQL> grant read, write, execute on directory bkp_dir to bkp;
SQL> connect bkp/rmanbkp SQL> create table bkp ( 2 line varchar2(255) 3 ) 4 organization external ( 5 type oracle_loader 6 default directory BKP_DIR 7 access parameters ( 8 records delimited by newline 9 preprocessor BKP_DIR:'run_backup.sh' 10 fields terminated by ';' ldrtrim 11 reject rows with all null fields 12 ) 13 location ('backup.rmn') 14 ) 15 reject limit unlimited;
SQL> create or replace procedure run_backup is 2 arrBackupLog backup_log; 3 4 cursor curBackupErrorsExist is 5 select 1 from dual 6 where exists ( 7 select 1 from table (arrBackupLog) 8 where column_value like 'RMAN-%' 9 ); 10 11 nDummy number(1); 12 bErrorsFound boolean; 13 begin 14 -- run weekly rman backup script 15 select line 16 bulk collect into arrBackupLog 17 from bkp; 18 -- report backup 19 open curBackupErrorsExist; 20 fetch curBackupErrorsExist into nDummy; 21 bErrorsFound := curBackupErrorsExist%found; 22 close curBackupErrorsExist; 23 24 if bErrorsFound then 25 dbms_output.put_line ('BACKUP FAILED'); 26 else 27 dbms_output.put_line ('BACKUP SUCCEEDED'); 28 end if; 29 end run_backup; 30 /
SQL> begin 2 dbms_scheduler.create_job ( 3 job_name => 'DAILY_BACKUP' 4 , job_type => 'STORED_PROCEDURE' 5 , job_action => 'run_backup' 6 , start_date => systimestamp 7 , repeat_interval => 'FREQ=DAILY;BYHOUR=04;BYMINUTE=0;BYSECOND=0' 8 , comments => 'Run daily RMAN backup' 9 , enabled => true 10 ); 11 end; 12 /
Source: https://habr.com/ru/post/136423/
All Articles