Tuesday, January 24, 2017

Crontab Necessary For DBA





·        The * means all the possible unit — i.e every minute of every hour through out the year. More than using this * directly, you will find it very useful in the following cases

·        Please note that the time field uses 24 hours format. So, for 11 AM use 11, and for 11 PM use 23.

How to View Crontab Entries?
View Current Logged-In User’s Crontab entries

To view your crontab entries type crontab -l from your unix account as shown below.

oracle@servername$crontab –l

·        How to Edit Crontab Entries ?
We can add or edit crontab entries by typing crontab –e in unix prompt as shown below



 oracle@servername$crontab –e

Some Exmples are given below: 

·        Example 1. Job to Run  Once a day except Sunday 
The basic usage of the job is to run once day as show below. This will take incremental backup everyday except Sunday on  10:30 PM  

30 10 * * 1,2,3,4,5,6 /u01/app/oracle/backup/L1-backup
§  30 – 30th Minute
§  22 – 10 PM
§  * – Everyday
§  * – All month (Jan)
§  1-6 – Every day of the week execpt sunday

Example 2. Job to Run On Every Sunday

The basic usage of cron is to execute a job on Every as shown below. This will execute the Full backup shell script (full-backup) on sunday 12:30 AM.


30 00 * * 0 /u01/app/oracle/backup/full-backup
§  30 – 30th Minute
§  00 – 12 AM
§  * – Any day of month
§  * – All Month
§  0 – Run On Sunday

Example 3. Job To Run Specific Time
The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 28th Jan 12:30 AM.


30 00 28 01 * /u01/app/oracle/backup/full-backup
§  30 – 30th Minute
§  00 – 12 AM
§  28 – 28th Day
§  01 – 1th Month (Jan)
§  * – Every day of the week

Example 4. Job To Run More Than One Instance (e.g. Twice a Day)
The following script take a incremental backup twice a day every day.

This example executes the specified incremental backup shell script (incremental-backup) at 11:00 and 16:00 on every day. The comma separated value in a field specifies that the command needs to be executed in all the mentioned time.

00 11,16 * * * /u01/app/oracle/backup/bin/incremental-backup
§  00 – 0th Minute (Top of the hour)
§  11,16 – 11 AM and 4 PM
§  * – Every day
§  * – Every month
§  * – Every day of the week

Example 5. Job To Run Specific Range of Time (e.g. Only on Weekdays)
If you wanted a job to be scheduled for every hour with in a specific range of time then use the following.
Cron Job everyday during working hours
This example checks the status of the database everyday (including weekends) during the working hours 9 a.m – 6 p.m
00 09-18 * * * /u01/app/oracle/backup/bin/check-db-status
§  00 – 0th Minute (Top of the hour)
§  09-18 – 9 am, 10 am,11 am, 12 am, 1 pm, 2 pm, 3 pm, 4 pm, 5 pm, 6 pm
§  * – Every day
§  * – Every month
§  * – Every day of the week
Cron Job every weekday during working hours
·        

Friday, January 20, 2017

Stepwise taking RMAN Incremental Cumulative L1 backup(Linux Server)

Stepwise taking RMAN Incremental Cumulative L1 backup(Linux Server)
 
Step 1
---------
Create an rcv file on server.
 
vi rman_incr_L1.rcv
 
Step 2
---------
Enter the following command in rcv file and save it (wq! used to save the file)
 
run {
allocate channel c1 type disk format='/RMAN/Full_BKP/Full_bkp_L1_%d_%s_%t_%U';
allocate channel c2 type disk format='/RMAN/Full_BKP/Full_bkp_L1_%d_%s_%t_%U';
allocate channel c3 type disk format='/RMAN/Full_BKP/Full_bkp_L1_%d_%s_%t_%U';
allocate channel c4 type disk format='/RMAN/Full_BKP/Full_bkp_L1_%d_%s_%t_%U';
backup as compressed backupset incremental level 1 cumulative database;
delete noprompt archivelog all completed before 'sysdate -.25' backed up 0 times to disk;
crosscheck archivelog all;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
exit;
 
 
this run block will the Incremental Rman L1 cumulative backup and delete the achivelog.
 
Step 3
---------
take the path where rcv file is created.
 
pwd (command is used for that)
 
Step 4
---------
 
Setup the env. and Run the rcv file from nohup
 
export ORACLE_SID=instance_name
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1
export PATH=$PATH:/u01/app/oracle/product/11.2.0.4/dbhome_1/bin
DT=$(date +"%F")
nohup /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/rman target / cmdfile=/RMAN/scripts/rman_incr_L1.rcv log=/RMAN/scripts/rman_incr_L1_$DT.log &
 
 
 
Optional Step: (Schedule it in crontab)
 
Step 1
---------
create a shell script like RMAN_INCR_L1.sh and put the following entry and save it
 
for example I have create the RMAN_INCR_L1.sh script in /u01/app/oracle/scripts
 
vi rman_incr_L1.sh
 
export ORACLE_SID=instance_name
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1
export PATH=$PATH:/u01/app/oracle/product/11.2.0.4/dbhome_1/bin
DT=$(date +"%F")
nohup /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/rman target / cmdfile=/RMAN/scripts/rman_incr_L1.rcv log=/RMAN/scripts/rman_incr_L1_$DT.log &
 
 
step 2
----------
Invoke crontab editor
 
crontab -e and edit it like below
 
00 18 * * 1,2,3,4,5,6 sh /u01/app/oracle/scripts/RMAN_INCR_L1.sh >> /u01/app/oracle/scripts/RMAN_INCR_L1.log
 
 
This will allow the script to run on every night at 6 PM server time zone
 
                                                
 

Stepwise taking RMAN Full level 0 backup(Linux Server)

Step wise taking RMAN Full level 0 backup(Linux Server)

Step 1
---------
Create an rcv file on server.

vi rman_full_L0.rcv

Step 2
---------

Enter the following command in rcv file and save it (wq! used to save the file)

run {
allocate channel c1 type disk format='/RMAN/Full_BKP/Full_bkp_L0_%d_%s_%t_%U';
allocate channel c2 type disk format='/RMAN/Full_BKP/Full_bkp_L0_%d_%s_%t_%U';
allocate channel c3 type disk format='/RMAN/Full_BKP/Full_bkp_L0_%d_%s_%t_%U';
allocate channel c4 type disk format='/RMAN/Full_BKP/Full_bkp_L0_%d_%s_%t_%U';
backup as compressed backupset incremental level 0 database plus archivelog delete input;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete ;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
exit;

This run block will the full Rman L0 backup with archivelog and delete the achivelog,expired and obsolete backup  as well.

Step 3
---------
take the path where rcv file is created.

pwd (command is used for that)

Step 4
---------
Setup the env. and Run the rcv file from nohup

export ORACLE_SID=instance_name
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1
export PATH=$PATH:/u01/app/oracle/product/11.2.0.4/dbhome_1/bin
DT=$(date +"%F")
nohup /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/rman target / cmdfile=/RMAN/scripts/rman_full_L0.rcv log=/RMAN/scripts/rman_full_L0_$DT.log &


Optional Step: (Schedule it in crontab)

Step 1
---------
Create a shell script like rman_full_l0.sh and put the following entry and save it

##for example I have create the sh script in /u01/app/oracle/scripts

vi rman_full_l0.sh

export ORACLE_SID=instance_name
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1
export PATH=$PATH:/u01/app/oracle/product/11.2.0.4/dbhome_1/bin
DT=$(date +"%F")
nohup /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/rman target / cmdfile=/RMAN/scripts/rman_full_L0.rcv log=/RMAN/scripts/rman_full_L0_$DT.log &

step 2
----------
Invoke crontab editor

crontab -e and edit it like below

00 20 * * 0 sh /u01/app/oracle/scripts/RMAN_FULL_L0.sh >> /u01/app/oracle/scripts/RMAN_FULL_L0.log

This will allow the script to run on every sunday night at 8 PM server time zone