Being a DBA it is your key responsibility to set a proper backup strategy. Today we will see how we can schedule backup :

Step 1 : Create script to take backup , Here I have created linux shell script

[oracle@prod-18c u01]$ cat bkp_schedule.sh 
rman target "'/ as sysbackup'" > /u01/backup_`date +%d_%m`.log  <<EOF
backup incremental level 1 device type disk tag '%Tag' database;
backup device type disk tag '%Tag'archivelog all not backed up
delete input;
run {
allocate channel backup_everyday type disk maxpiecesize 250M;
backup tag '%Tag' current controlfile;
release channel backup_everyday;
}
delete noprompt obsolete
exit;
EOF
echo "End of my_sched_bkup.sh" >> /u01/backup_`date +%d_%m`.log
exit
[oracle@prod-18c u01]$

Check above backup script , I have used quite a few RMAN parameters to make a proper backup script like maxpiecesize , backup of current controlfile , deletion of obsolete backups etc

Lets run this file to check it works correctly.

[oracle@prod-18c u01]$ ./bkp_schedule.sh

Let’s check output in log file , as we can see in backup script , backup log will be restored in /u01 directory with current date.

So go to /u01 directory and check backup log.

[oracle@prod-18c ~]$ date
Wed May 22 23:00:15 IST 2019
[oracle@prod-18c ~]$ cd /u01
[oracle@prod-18c u01]$ 
[oracle@prod-18c u01]$ cat backup_22_05.log 

Recovery Manager: Release 12.2.0.1.0 - Production on Wed May 22 23:56:21 2019

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL1 (DBID=1383488253)

RMAN> 
Starting backup at 22-MAY-19
using target database control file instead of re
overy catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=72 device type=DISK
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/ORCL1/datafile/o1_mf_system_g56bzr71_.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/ORCL1/datafile/o1_mf_sysaux_g56c4gwz_.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/ORCL1/datafile/o1_mf_undotbs1_g56c8082_.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/ORCL1/datafile/o1_mf_users_g56c8cf3_.dbf
channel ORA_DISK_1: starting piece 1 at 22-MAY-19
channel ORA_DISK_1: finished piece 1 at 22-MAY-19
piece handle=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/backupset/2019_05_22/o1_mf_nnnd1__TAG_ggc52s3s_.bkp tag=%TAG comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/ORCL1/80C5B383246F06B2E0531201A8C09E95/datafile/o1_mf_sysaux_g56fjoqy_.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/ORCL1/80C5B383246F06B2E0531201A8C09E95/datafile/o1_mf_system_g56fjomp_.dbf
input datafile file number=00011 name=/u01/app/oracle/oradata/ORCL1/80C5B383246F06B2E0531201A8C09E95/datafile/o1_mf_undotbs1_g56fjoqz_.dbf
input datafile file number=00019 name=/u01/app/oracle/oradata/ORCL1/80C5B383246F06B2E0531201A8C09E95/datafile/o1_mf_tsa_g60sbrnw_.dbf
input datafile file number=00020 name=/u01/app/oracle/oradata/ORCL1/80C5B383246F06B2E0531201A8C09E95/datafile/o1_mf_tsb_g60scc47_.dbf
input datafile file number=00021 name=/u01/app/oracle/oradata/ORCL1/80C5B383246F06B2E0531201A8C09E95/datafile/o1_mf_tsc_g60scts8_.dbf
input datafile file number=00022 name=/u01/app/oracle/oradata/ORCL1/80C5B383246F06B2E0531201A8C09E95/datafile/o1_mf_tsd_g60sdjw8_.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/ORCL1/80C5B383246F06B2E0531201A8C09E95/datafile/o1_mf_users_g56fmk1x_.dbf
channel ORA_DISK_1: starting piece 1 at 22-MAY-19
channel ORA_DISK_1: finished piece 1 at 22-MAY-19
piece handle=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/80C5B383246F06B2E0531201A8C09E95/backupset/2019_05_22/o1_mf_nnnd1__TAG_ggc547cn_.bkp tag=%TAG comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00014 name=/u01/app/oracle/oradata/ORCL1/8183F1693BDD1468E0531201A8C02271/datafile/o1_mf_sysaux_g5zcg9k5_.dbf
input datafile file number=00013 name=/u01/app/oracle/oradata/ORCL1/8183F1693BDD1468E0531201A8C02271/datafile/o1_mf_system_g5zcg9hv_.dbf
input datafile file number=00015 name=/u01/app/oracle/oradata/ORCL1/8183F1693BDD1468E0531201A8C02271/datafile/o1_mf_undotbs1_g5zcg9k7_.dbf
channel ORA_DISK_1: starting piece 1 at 22-MAY-19
channel ORA_DISK_1: finished piece 1 at 22-MAY-19
piece handle=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/8183F1693BDD1468E0531201A8C02271/backupset/2019_05_22/o1_mf_nnnd1__TAG_ggc550yj_.bkp tag=%TAG comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:26
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/app/oracle/oradata/ORCL1/datafile/o1_mf_sysaux_g56ch5h5_.dbf
skipping datafile 00006 because it has not changed
input datafile file number=00005 name=/u01/app/oracle/oradata/ORCL1/datafile/o1_mf_system_g56ch5lh_.dbf
skipping datafile 00005 because it has not changed
input datafile file number=00008 name=/u01/app/oracle/oradata/ORCL1/datafile/o1_mf_undotbs1_g56ch5o2_.dbf
skipping datafile 00008 because it has not changed
channel ORA_DISK_1: backup cancelled because all files were skipped
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00017 name=/u01/app/oracle/oradata/ORCL1/818DC149F5282394E0531201A8C0C446/datafile/o1_mf_sysaux_g60nm8r7_.dbf
skipping datafile 00017 because it has not changed
input datafile file number=00016 name=/u01/app/oracle/oradata/ORCL1/818DC149F5282394E0531201A8C0C446/datafile/o1_mf_system_g60nm8qh_.dbf
skipping datafile 00016 because it has not changed
input datafile file number=00018 name=/u01/app/oracle/oradata/ORCL1/818DC149F5282394E0531201A8C0C446/datafile/o1_mf_undotbs1_g60nm8r8_.dbf
skipping datafile 00018 because it has not changed
channel ORA_DISK_1: backup cancelled because all files were skipped
Finished backup at 22-MAY-19

Starting Control File and SPFILE Autobackup at 22-MAY-19
piece handle=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/autobackup/2019_05_22/o1_mf_s_1008979094_ggc560xf_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 22-MAY-19

RMAN> 2> 
Starting backup at 22-MAY-19
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=8 RECID=7 STAMP=1008804029
input archived log thread=1 sequence=9 RECID=8 STAMP=1008963480
input archived log thread=1 sequence=10 RECID=9 STAMP=1008976635
input archived log thread=1 sequence=11 RECID=10 STAMP=1008979108
channel ORA_DISK_1: starting piece 1 at 22-MAY-19
channel ORA_DISK_1: finished piece 1 at 22-MAY-19
piece handle=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/backupset/2019_05_22/o1_mf_annnn__TAG_ggc56grn_.bkp tag=%TAG comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/archivelog/2019_05_20/o1_mf_1_8_gg5t6zf2_.arc RECID=7 STAMP=1008804029
archived log file name=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/archivelog/2019_05_22/o1_mf_1_9_ggboxyvf_.arc RECID=8 STAMP=1008963480
archived log file name=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/archivelog/2019_05_22/o1_mf_1_10_ggc2s2os_.arc RECID=9 STAMP=1008976635
archived log file name=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/archivelog/2019_05_22/o1_mf_1_11_ggc56bnn_.arc RECID=10 STAMP=1008979108
Finished backup at 22-MAY-19

Starting Control File and SPFILE Autobackup at 22-MAY-19
piece handle=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/autobackup/2019_05_22/o1_mf_s_1008979127_ggc57048_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 22-MAY-19

RMAN> 2> 3> 4> 5> 
released channel: ORA_DISK_1
allocated channel: backup_everyday
channel backup_everyday: SID=72 device type=DISK

Starting backup at 22-MAY-19
channel backup_everyday: starting full datafile backup set
channel backup_everyday: specifying datafile(s) in backup set
including current control file in backup set
channel backup_everyday: starting piece 1 at 22-MAY-19
channel backup_everyday: finished piece 1 at 22-MAY-19
piece handle=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/backupset/2019_05_22/o1_mf_ncnnf__TAG_ggc579rx_.bkp tag=%TAG comment=NONE
channel backup_everyday: backup set complete, elapsed time: 00:00:01
Finished backup at 22-MAY-19

Starting Control File and SPFILE Autobackup at 22-MAY-19
piece handle=/u01/app/oracle/fast_recovery_area/orcl1/ORCL1/autobackup/2019_05_22/o1_mf_s_1008979139_ggc57dov_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 22-MAY-19

released channel: backup_everyday

RMAN> 

Recovery Manager complete.
End of my_sched_bkup.sh
[oracle@prod-18c u01]$ 

Step 2 : Schedule backup , either we can schedule it using Operating system scheduler or Oracle Database Scheduler. Here I have created a job to schedule backup :

SQL> begin
  2  dbms_scheduler.create_job(
job_name => 'bkp_schedule',
job_type => 'EXECUTABLE',
job_action => '/u01/bkp_schedule.sh',
start_date => '22-MAY-18 11:52:00PM',
repeat_interval => 'FREQ=DAILY',
enabled => true,
auto_drop => false,
comments => 'backup schedule');
end;
/  3    4    5    6    7    8    9   10   11   12  

PL/SQL procedure successfully completed.

Here I have created the job which will run daily from today onwards. My job schedule name is BKP_SCHEDULE . Let’s check in Data Dictionary views that it is scheduled or not.

SQL> col job_name for a20
SQL> SELECT JOB_NAME, ENABLED, STATE, RUN_COUNT, FAILURE_COUNT FROM DBA_SCHEDULER_JOBS WHERE JOB_NAME = 'BKP_SCHEDULE';

JOB_NAME	     ENABL STATE	    RUN_COUNT FAILURE_COUNT
-------------------- ----- --------------- ---------- -------------
BKP_SCHEDULE	     TRUE  SCHEDULED		    0		  0

SQL> 

We can see here it is scheduled.

Thank you for giving your valuable time to read the above information.

If you want to be updated with all our articles send us the Invitation or Follow us:

Telegram Channel: https://t.me/helporacle

Skant Gupta’s LinkedIn: www.linkedin.com/in/skantali/

Joel Perez’s LinkedIn: Joel Perez’s Profile

LinkedIn Group: Oracle Cloud DBAAS

Facebook Page: OracleHelp

About The Author

Comments

  1. Ravin Maharaj

    Hi, What if I have more than one database to backup? Is it possible to create a generic shell script where I can pass the Oracle SID through to the shell script and then schedule the backup via dbms_scheduler

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.