Crontab job for RMAN Backup as Level 0 and level 1
Posted by Mir Sayeed Hassan on February 18th, 2018
Crontab job for RMAN Backup as Level 0 and level 1
Create all the directories and give the permission in /backup folder
[oracle@Testdb ~]$ cd /backup/rman/
Example:
$mkdir friday_level_0
And others
[oracle@Testdb rman]$ ls friday_level_0 monday_level_1 saturday_level_1 sunday_level_1 thursday_level_1 tuesday_level_1 wednesday_level_1
$chmod –R 777 *
Go to the /home/oracle and create the directory as scripts
$mkdir scripts
Friday
[oracle@Testdb scripts]$ vi friday export ORACLE_SID=test export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 /u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog@/home/oracle/scripts/friday.rcv > /backup/rman/friday_level_0/rman`date +%F`.log
[oracle@Testdb scripts]$ vi friday.rcv
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
crosscheck backup;
delete backup;
backup as compressed backupset
incremental level 0
skip inaccessible
tag friday_level_0
format '/backup/rman/friday_level_0/TEST_df_%U'
database;
backup spfile format '/backup/rman/friday_level_0/TEST_spf_%T.ora';
sql 'alter system archive log current';
backup as compressed backupset
tag archivelog_friday
format '/backup/rman/friday_level_0/TEST_arch_%U'
archivelog all not backed up 1 times;
crosscheck archivelog all;
delete archivelog until time 'SYSDATE - 3';
crosscheck backup;
delete obsolete;
}
Saturday
[oracle@Testdb scripts]$ vi saturday export ORACLE_SID=test export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 /u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog@/home/oracle/scripts/saturday.rcv > /backup/rman/saturday_level_1/rman`date +%F`.log
[oracle@Testdb scripts]$ vi saturday.rcv
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup as compressed backupset
incremental level 1 cumulative
skip inaccessible
tag saturday_level_1
format '/backup/rman/saturday_level_1/TEST_df_%U'
database;
backup spfile format '/backup/rman/saturday_level_1/TEST_spf_%T.ora';
sql 'alter system archive log current';
backup as compressed backupset
tag archivelog_saturday
format '/backup/rman/saturday_level_1/TEST_arch_%U'
archivelog all not backed up 1 times;
crosscheck archivelog all;
delete archivelog until time 'SYSDATE - 3';
crosscheck backup;
delete obsolete;
}
Sunday
[oracle@Testdb scripts]$ vi sunday export ORACLE_SID=test export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 /u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog@/home/oracle/scripts/sunday.rcv > /backup/rman/sunday_level_1/rman`date +%F`.log
[oracle@Testdb scripts]$ vi sunday.rcv
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup as compressed backupset
incremental level 1 cumulative
skip inaccessible
tag sunday_level_1
format '/backup/rman/sunday_level_1/TEST_df_%U'
database;
backup spfile format '/backup/rman/sunday_level_1/TEST_spf_%T.ora';
sql 'alter system archive log current';
backup as compressed backupset
tag archivelog_sunday
format '/backup/rman/sunday_level_1/TEST_arch_%U'
archivelog all not backed up 1 times;
crosscheck archivelog all;
delete archivelog until time 'SYSDATE - 3';
crosscheck backup;
delete obsolete;
}
Monday
[oracle@Testdb scripts]$ vi monday export ORACLE_SID=test export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 /u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog@/home/oracle/scripts/monday.rcv > /backup/rman/monday_level_1/rman`date +%F`.log
[oracle@Testdb scripts]$ vi monday.rcv
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup as compressed backupset
incremental level 1 cumulative
skip inaccessible
tag monday_level_1
format '/backup/rman/monday_level_1/TEST_df_%U'
database;
backup spfile format '/backup/rman/monday_level_1/TEST_spf_%T%s.ora';
sql 'alter system archive log current';
backup as compressed backupset
tag archivelog_monday
format '/backup/rman/monday_level_1/TEST_arch_%U'
archivelog all not backed up 1 times;
crosscheck archivelog all;
delete archivelog until time 'SYSDATE - 3';
crosscheck backup;
delete obsolete;
}
Thuesday
[oracle@Testdb scripts]$ vi tuesday export ORACLE_SID=test export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 /u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog@/home/oracle/scripts/tuesday.rcv ; /backup/rman/tuesday_level_1/rman`date +%F`.log
[oracle@Testdb scripts]$ vi tuesday.rcv
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup as compressed backupset
incremental level 1 cumulative
skip inaccessible
tag tuesday_level_1
format '/backup/rman/tuesday_level_1/TEST_df_%U'
database;
backup spfile format '/backup/rman/tuesday_level_1/TEST_spf_%T.ora';
sql 'alter system archive log current';
backup as compressed backupset
tag archivelog_tuesday
format '/backup/rman/tuesday_level_1/TEST_arch_%U'
archivelog all not backed up 1 times;
crosscheck archivelog all;
delete archivelog until time 'SYSDATE - 3';
crosscheck backup;
delete obsolete;
}
Wednesday
[oracle@Testdb scripts]$ vi wednesday export ORACLE_SID=test export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 /u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog@/home/oracle/scripts/wednesday.rcv > /backup/rman/wednesday_level_1/rman`date +%F`.log
[oracle@Testdb scripts]$ vi wednesday.rcv
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup as compressed backupset
incremental level 1 cumulative
skip inaccessible
tag wednesday_level_1
format '/backup/rman/wednesday_level_1/TEST_df_%U'
database;
backup spfile format '/backup/rman/wednesday_level_1/TEST_spf_%T.ora';
sql 'alter system archive log current';
backup as compressed backupset
tag archivelog_wednesday
format '/backup/rman/wednesday_level_1/TEST_arch_%U'
archivelog all not backed up 1 times;
crosscheck archivelog all;
delete archivelog until time 'SYSDATE - 3';
crosscheck backup;
delete obsolete;
}
Thursday
[oracle@Testdb scripts]$ vi hursday export ORACLE_SID=test export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 /u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog@/home/oracle/scripts/thursday.rcv > /backup/rman/thursday_level_1/rman`date +%F`.log
[oracle@Testdb scripts]$ vi thursday.rcv
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup as compressed backupset
incremental level 1 cumulative
skip inaccessible
tag thursday_level_1
format '/backup/rman/thursday_level_1/TEST_df_%U'
database;
backup spfile format '/backup/rman/thursday_level_1/TEST_spf_%T.ora';
sql 'alter system archive log current';
backup as compressed backupset
tag archivelog_thursday
format '/backup/rman/thursday_level_1/TEST_arch_%U'
archivelog all not backed up 1 times;
crosscheck archivelog all;
delete archivelog until time 'SYSDATE - 3';
crosscheck backup;
delete obsolete;
}
Level – 0
[oracle@Testdb scripts]$ vi level-0.rcv export ORACLE_SID=test export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 /u01/app/oracle/product/11.2.0/dbhome_1/bin/rman target / nocatalog@/home/oracle/scripts/level-0.rcv > /backup/SWINT_rman`date +%Y%m%d`.log
[oracle@Testdb scripts]$ vi level-0.rcv
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
configure controlfile autobackup format for device type disk to '/backup/TEST_cf%F';
backup as compressed backupset section size 20G
incremental level 0
skip inaccessible
tag friday_level_0
format '/backup/TEST_df_t%t_s%s_p%p_%T'
database;
backup spfile format '/backup/TEST_spf_%T.ora';
}
Login as the root and create the crontab command as shown below
[root@Testdb etc]# pwd /etc
Syntax for crontab:
[root@Testdb etc]# vi crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
# For details see man 4 crontabs
# Example of job definition:
# .—————- minute (0 – 59)
# | .————- hour (0 – 23)
# | | .———- day of month (1 – 31)
# | | | .——- month (1 – 12) OR jan,feb,mar,apr …
# | | | | .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
Then login as oracle user as su – oracle and create the crontab –e file
[oracle@Testdb ~]$ crontab –e 0 1 * * 2 /home/oracle/scripts/tuesday 0 1 * * 3 /home/oracle/scripts/wednesday 0 1 * * 4 /home/oracle/scripts/thursday 0 1 * * 5 /home/oracle/scripts/friday 0 1 * * 6 /home/oracle/scripts/saturday 0 1 * * 0 /home/oracle/scripts/sunday 0 1 * * 1 /home/oracle/scripts/Monday






