Search

Join this Blog for direct reference of any post into your inbox. To join just click on "Join this Site" under "Follower" then Login with your Email.*** DECLARATION: I Maintain this Blog for Helping Myself While at Work and Welcome any body Needing Help!!!.*** CAUTION: Using any of the script from this Blog may contain at Own Risk. These scripts May or May not have been Tested.***

Saturday, 2 June 2012

Script: Crontab Use for RMAN Backup

On the behalf of Gaurav I am posting this script. He has tested this script and documented well. Hope it will be useful for all of us. Thanks to him for such as useful contribution.

Note :Make Sure all Script has Right RW Permissions
[oracle@Gvashist ~]$ vi /dba/gv.sh

#!/bin/ksh
ORACLE_BASE=/dba/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export
LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdb
ms/jlib; export CLASSPATH
exp system/gaurav@mydb file='/dba/exp.dmp' log='/dba/exp.log' feedback=5000
buffer=2000 owner=gaurav statistics=none compress=y
[oracle@Gvashist ~]$ crontab -l
* * * * *oracle /dba/gv.sh
You have new mail in /var/spool/mail/oracle
[oracle@Gvashist~]$ tail -30 /var/spool/mail/oracle
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting statistics
Export terminated successfully without warnings.
[oracle@Gvashist~]$
If I don’t want mail so make some changes in crontab file like this :-
* * * * *oracle /dba/gv.sh > /dba/mylog.log
Now my /dba/mylog.log show the Output there.
Shell Script: RMAN Backup
[oracle@racnode2 ~]$ cat /dba/rman.sh
#!/bin/bash
ORACLE_BASE=/dba/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export
ORACLE_HOME
ORACLE_SID=dba; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export
LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOM
E/rdbms/jlib; export CLASSPATH
# Connect to the database. Change this to Sys logon if not using /
rman target / @'/dba/bak.rcv' ( Need another Script which one Hold RMAN cmd )
Rman Cmd Script --)
[oracle@racnode2 ~]$ cat /dba/bak.rcv
run
{
allocate channel ch1 device type disk format '/dba/%U.bak';
backup archivelog all;
release channel ch1;
}
Crontab syntax
A crontab file has six fields for specifying minute, hour, day of month, month, day of
week and the command to be run at that interval. See below:
* * * * * command to be executed
|||||
| | | | +-----day of week (0 -6) (Sunday=0)
| | | +-------month (1 -12)
| | +---------day of month (1 -31)
| +-----------hour (0 -23)
+-------------min (0 -59)
Examples
Writing a crontab file can be a somewhat confusing for first time users, therefore I have
listed below some crontab examples:
* * * * * <command> #Runs every minute
30 * * * * <command> #Runs at 30 minutes past the hour
45 6 * * * <command> #Runs at 6:45 am every day
45 18 * * * <command> #Runs at 6:45 pm every day
00 1 * * 0 <command> #Runs at 1:00 am every Sunday
00 1 * * 7 <command> #Runs at 1:00 am every Sunday
00 1 * * Sun <command> #Runs at 1:00 am every Sunday
30 8 1 * * <command> #Runs at 8:30 am on the first day of every month
00 0-23/2 02 07 * <command> #Runs every other hour on the 2nd of July

1 comments: