Tuesday 27 May 2014

Crontab is lost !!!!,....... consider taking a backup before and after adding an entry or modifying the crontab ......... You may write a custom script which is automatically take the backup of crontab....... ( You may use the script below)


Note :
please use the script carefully before deploying in your server its advised to implement in test server 

Note : 
Implementing or trying any of the advice from this blog is at your own risk.



# Scripts Start
# This script will generate a crontab backup file and will email to mentioned ids
# Script Created Karthikeyan.K
# karthik-oracledba.blogspot.in
#================================================================================
#Below syntax will create a new file with present date with name specified.
START_DT=`date '+%d_%m_%Y'`
file_name=$HOME/cron_backup_$START_DT.txt

crontab -l > $file_name

/usr/bin/uuencode $file_name $file_name | mailx -s "The crontab backup of HOST(IP)" ____@__.com

# Below will delete 30 Days old crontab
find $HOME/cron_backup_*.txt -mtime +30 -exec rm {} \;

#### IMPORTANT THE ABOVE SYNTAX WILL DELETE ANY FILE IN HOME DIRECTORY WHICH HAS THE NAMING CONVENTION cron_backup_*.txt !!!!!!!!! 

#=================================================================================
# Scripts End








Tip : 
===

place all your cron job shell scripts in one directory this will help in taking a backup of script directory as well if possible direct this parent folder to tape backup

Lost oratab file ? OR Started the db with wrong ORACLE_HOME ? how to find the right ORACLE_HOME which was used to start up the oracle DB


1. A DB was started by mistake with setting different oracle home their was mutiple homes installed in test environment with 30 database running
2. Used below method
3. find the pmon process id  with ps -ef|grep pmon
4. Navigate to cd /proc folder
5. find a folder under /proc with process id  ls -lrt |grep <pmon_processid>
6. Navigate to process id folder and do ls -lrt you will find the path which was set for that process to spawn.



Example - 1
======
testhost1:orcl1:/opt/app>ps -ef|grep pmon
oracle    6237  6222  0 21:30 pts/1    00:00:00 grep pmon
oracle   28245     1  0 Feb16 ?        00:02:48 ora_pmon_orcl1

testhost1:orcl1:/opt/app>cd /proc


testhost1:orcl1:/proc>ls -lrt |grep 28245
dr-xr-xr-x  5 oracle     oinstall              0 2014-02-16 23:11 28245


testhost1:orcl1:/proc>cd 28245
testhost1:orcl1:/proc/28245>ls -lrt
total 0
-r--r--r-- 1 oracle oinstall 0 2014-02-16 23:11 stat
-r--r--r-- 1 oracle oinstall 0 2014-02-16 23:11 status
-r--r--r-- 1 oracle oinstall 0 2014-02-16 23:11 maps
dr-x------ 2 oracle oinstall 0 2014-02-16 23:11 fd
-r--r--r-- 1 oracle oinstall 0 2014-02-16 23:11 statm
-r-------- 1 oracle oinstall 0 2014-02-16 23:11 limits
-r--r--r-- 1 oracle oinstall 0 2014-02-16 23:11 cmdline
lrwxrwxrwx 1 oracle oinstall 0 2014-02-16 23:30 exe -> /opt/app/oracle/product/11.2.0.4/db_4/bin/oracle
dr-xr-xr-x 3 oracle oinstall 0 2014-02-17 22:11 task
dr-xr-xr-x 2 oracle oinstall 0 2014-02-17 22:11 attr
-rw------- 1 oracle oinstall 0 2014-02-22 01:25 seccomp
-r--r--r-- 1 oracle oinstall 0 2014-02-22 01:25 numa_maps
-rw------- 1 oracle oinstall 0 2014-02-22 01:25 mem
-r-------- 1 oracle oinstall 0 2014-02-22 01:25 environ
lrwxrwxrwx 1 oracle oinstall 0 2014-02-22 01:25 cwd -> /opt/app/oracle/product/11.2.0.4/db_4/dbs
-r-------- 1 oracle oinstall 0 2014-02-22 01:25 auxv
-r--r--r-- 1 oracle oinstall 0 2014-02-22 01:25 wchan
-r--r--r-- 1 oracle oinstall 0 2014-02-22 01:25 smaps
lrwxrwxrwx 1 oracle oinstall 0 2014-02-22 01:25 root -> /
-r--r--r-- 1 oracle oinstall 0 2014-02-22 01:25 oom_score
-rw-r--r-- 1 oracle oinstall 0 2014-02-22 01:25 oom_adj
-r--r--r-- 1 oracle oinstall 0 2014-02-22 01:25 mounts
-rw------- 1 oracle oinstall 0 2014-02-22 01:25 mapped_base
-rw-r--r-- 1 oracle oinstall 0 2014-02-22 01:25 loginuid
-r--r--r-- 1 oracle oinstall 0 2014-02-22 01:25 cpuset
testhost1:orcl1:/proc/28245>

Here the ORACLE HOME is /opt/app/oracle/product/11.2.0.4/db_4

Remember process id folder will exist for current running process.

Monday 26 May 2014

Spool file in RMAN prompt

This will be very useful when you quickly need a huge output from RMAN.

Check 2 examples

Below is the example  1
=====================

testhost1 $
testhost1 $ ls -lrt list_bkp_controlfile_sysdate
list_bkp_controlfile_sysdate: No such file or directory
testhost1 $ rman target /

Recovery Manager: Release 11.2.0.2.0 - Production on Tue May 27 01:44:12 2014

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

connected to target database: ORCL1 (DBID=394612220)

RMAN> spool log to 'list_bkp_controlfile_sysdate';
RMAN> list backup of controlfile  completed after 'sysdate-1';
RMAN> exit
testhost1 $ ls -lrt list_bkp_controlfile_sysdate
-rw-------   1 oracle   dba         5788 May 27 01:45 list_bkp_controlfile_sysdate
testhost1 $ head list_bkp_controlfile_sysdate

Spooling started in log file: list_bkp_controlfile_sysdate

Recovery Manager11.2.0.2.0

RMAN>
using target database control file instead of recovery catalog

List of Backup Sets
===================
testhost1 $ tail list_bkp_controlfile_sysdate
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
56974   Full    68.75M     SBT_TAPE    00:00:46     26-MAY-14
        BP Key: 56974   Status: AVAILABLE  Compressed: NO  Tag: TAG20140526T221945
        Handle: ctrl_u78p99lc1_s60648_p1_t848622785   Media: U00880
  Control File Included: Ckp SCN: 11076235186143   Ckp time: 26-MAY-14

RMAN>

Recovery Manager complete.
testhost1 $ cat list_bkp_controlfile_sysdate |wc -l
     106
     










Below is the example  2
=====================
     
Remember this spool syntax will overright the file if already exists in present working directory 

you may use APPEND(From 10g onwards) to append on the existing file. use below syntax


testhost1 $ rman target /

Recovery Manager: Release 11.2.0.2.0 - Production on Tue May 27 01:46:00 2014

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

connected to target database: ORCL1 (DBID=394612220)

RMAN> spool log to 'list_bkp_controlfile_sysdate' append;
RMAN>  list backup of controlfile  completed after 'sysdate-2';
RMAN> exit
testhost1 $ ls -lrt list_bkp_controlfile_sysdate
-rw-------   1 oracle   dba        17127 May 27 01:46 list_bkp_controlfile_sysdate
testhost1 $ head list_bkp_controlfile_sysdate

Spooling started in log file: list_bkp_controlfile_sysdate

Recovery Manager11.2.0.2.0

RMAN>
using target database control file instead of recovery catalog

List of Backup Sets
===================
testhost1 $ tail list_bkp_controlfile_sysdate
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
56974   Full    68.75M     SBT_TAPE    00:00:46     26-MAY-14
        BP Key: 56974   Status: AVAILABLE  Compressed: NO  Tag: TAG20140526T221945
        Handle: ctrl_u78p99lc1_s60648_p1_t848622785   Media: U00880
  Control File Included: Ckp SCN: 11076235186143   Ckp time: 26-MAY-14

RMAN>

Recovery Manager complete.
testhost1 $
testhost1 $ cat list_bkp_controlfile_sysdate |wc -l
     303
testhost1 $