Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Script Name check_alert.sh Purpose Check the alert log file for any oracle error messages. Check if the listener is up and running. The alert log and listener are verified for all databases on the box. If any errors are found, an email is sent to the DBA. Parameters None Command Line $ ./check_alert.sh View Script Script Name check_db.sh Purpose To tnsping all Oracle databases on the network and page DBA if a database is not responding. This could be a cronjob run in specified intervals. The database names are obtained from tnsnames.ora file. The entries should be uniform. This script may not work as it is... you may have to make modifications based on your tnsnames.ora file entry formatting. This script is interested only in database names ending with 'OR'. Parameters None Command Line $ ./check_db.sh View Script Script Name check_server.sh Purpose To ping other servers on the network and page DBA if a server is not responding. This could be a cronjob run in specified intervals. Parameters None Command Line $ ./check_server.sh View Script Script Name compare_sid_db.sh Purpose vice versa. To compare and verify if all instances mentioned in /etc/oratab is up and running and Parameters None Command Line $ ./compare_sid_db.sh View Script Script Name dbalert.sh Purpose Apart from the functions of checkalert.sh script, this script logs into each oracle database and looks for potential space problems and invalid objects, triggers, etc. Calls a sql script dbalert.sql. Notifies the DBA of potential problems via email. Parameters None Command Line $ ./dbalert.sh View Shell Script Script Name SQL Script find_hogger.sh Purpose Script to identify the top 20 longest running oracle sessions and the user id, SID, Serial#, logon time, etc. Useful for high CPU bound systems with large number of users. Script also identifies processes without a oracle session. Parameters None Command Line $ ./find_hogger.sh View Script Script Name Sample Output find_ohome.sh Purpose Useful if you have multiple versions of oracle on the same box. This script returns the oracle home value accepting the SID name as parameter. This script is used in other scripts on Biju's DBA Page. Parameters ORACLE_SID Value Command Line $ ./find_ohome.sh TESTDB View Script Script Name sid.sh Purpose Useful if you have multiple instances of oracle on the same box with different oracle homes. This script helps you to choose the SID name you would like to work and assigns the correct oracle home and includes that in your unix path. Parameters None Command Line $ . ./sid.sh (make sure you specify "." before the file name - works only on ksh or sh) View Script Script Name tscoalesce.sh Purpose This script may be used as a cronjob to coalesce the tablespaces periodically. This is especially useful if all your tablespace pctincrease value is set to 0. Uses /etc/oratab to read all instance names, and operating system authentication to log into the database. Parameters None Command Line $ ./tscoalesce.sh View Script Question: Can you provide me a shell script that will accept oracle credentials, sql query to be executed and displays the output? Answer: The shell script given below prompts some basic information and displays the output of the SQL. You can use the same concept and hard-code some of these values in the shell-script itself and even run this script in the background to generate the output of an oracle sql query automatically (or use the oracle shell script from cron job). This script accepts following values from the user: Oracle username Oracle password Oracle SQL Query to be executed. Script validates the $ORACLE_HOME and $ORACLE_SID set in environment. Shell Script to Execute Query in Oracle This script allows you to enter the credential to login to oracle, and executes the query and displays the output. $ cat sql_query.sh #!/bin/bash # Validate the value of ORACLE_HOME # # If ORACLE_HOME is empty # if [ -z $ORACLE_HOME ] then echo "Set the ORACLE_HOME variable" exit 1 fi # If ORACLE_HOME doesn't exist # if [ ! -d $ORACLE_HOME ] then echo "The ORACLE_HOME $ORACLE_HOME does not exist" exit 1 fi # Validate the value of ORACLE_SID # if [ -z $ORACLE_SID ] then echo "Set the ORACLE_SID variable" exit 1 fi sid_dir=`echo $ORACLE_HOME | sed -n 's@^\(\/[^\/]\+\/\).*$@\1@;p'` # Check the given ORACLE_SID is valid. if [ ! -d $sid_dir/oradata/$ORACLE_SID ] then echo "The ORACLE_SID is invalid" exit 1 fi # Enter the username and password to login to oracle # echo "Enter the username" read username echo "Enter password" stty -echo read password stty echo # Get the query , no validation applied for query # echo "Enter the query" read query # Login and execute the query. echo "set feedback off verify off heading off pagesize 0 $query exit" | $ORACLE_HOME/bin/sqlplus -s $username/$password | while read output ; do echo $output done In database, SQL> select * from test; SNO ---------12 23 34 45 $ ./sql_query.sh Enter the username system Enter password Enter the query select SNO from test; 12 23 34 45 Before making Oracle Database available for any valid user, you must start up a database, create an instance of the database and choose the state in which the database starts. Startup Database 1. Create an instance of the database and Startup database in normal mode Before creating instance, we must check necessory variables first. $ env | grep ORACLE ORACLE_SID=viper ORACLE_HOME=/oracle/OraHome1 And then startup Oracle database in normal mode with svrmgrl command (From 8.1.x, you can start oracle database with SQL*Plus) $ svrmgrl Oracle Server Manager Release 3.1.6.0.0 - Production Copyright (c) 1997, 1999, Oracle Corporation. All Rights Reserved. Oracle8i Enterprise Edition Release 8.1.6.0.0 - Production With the Partitioning option JServer Release 8.1.6.0.0 - Production SVRMGR> connect internal Connected. SVRMGR> startup ORACLE instance started. Total System Global Area 376086952 bytes Fixed Size 94632 bytes Variable Size 49020928 bytes Database Buffers 326791168 bytes Redo Buffers 180224 bytes Database mounted. Database opened. SVRMGR> ** Startup Oracle Database with default location of a parameter file $ORACLE_HOME/dbs/initviper.ora 2. Startup listener The listener is a separate process that resides on the server. The listener receives incoming client connection requests and hands these requests to the server. Before client side can connect to Database server via Net8, we must start the listener process first. $ lsnrctl start LSNRCTL for DEC OSF/1 AXP: Version 8.1.6.0.0 - Production on 02-MAY-2001 05:59:37 (c) Copyright 1998, 1999, Oracle Corporation. All rights reserved. Starting /oracle/OraHome1/bin/tnslsnr: please wait... TNSLSNR for DEC OSF/1 AXP: Version 8.1.6.0.0 - Production System parameter file is /oracle/OraHome1/network/admin/listener.ora Log messages written to /oracle/OraHome1/network/log/listener.log Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC))) Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dec4100.exzilla.net)(PORT=1521))) Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dec4100.exzilla.net)(PORT=2481)) (PROTOCOL_STACK=(PRESENTATION=GIOP)(SESSION=RAW))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for DEC OSF/1 AXP: Version 8.1.6.0.0 - Production Start Date 02-MAY-2001 05:59:38 Uptime 0 days 0 hr. 0 min. 0 sec Trace Level off Security OFF SNMP OFF Listener Parameter File /oracle/OraHome1/network/admin/listener.ora Listener Log File /oracle/OraHome1/network/log/listener.log Services Summary... PLSExtProc has 1 service handler(s) dare has 1 service handler(s) venom has 1 service handler(s) viper has 1 service handler(s) The command completed successfully $ 3. Test connection We test all configuration (tnsnames.ora,sqlnet.ora) files that can work with the listener process with TNSPING command. $ tnsping viper TNS Ping Utility for DEC OSF/1 AXP: Version 8.1.6.0.0 - Production on 02-MAY-2001 06:02:21 (c) Copyright 1997 Oracle Corporation. All rights reserved. Attempting to contact (ADDRESS=(PROTOCOL=TCP)(HOST=dec4100.exzilla.net)(PORT=1521)) OK (310 msec) $ Shutdown Database 1. Shutdown listener $ lsnrctl stop LSNRCTL for DEC OSF/1 AXP: Version 8.1.6.0.0 - Production on 02-MAY-2001 05:59:29 (c) Copyright 1998, 1999, Oracle Corporation. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC))) The command completed successfully $ 2. Shutdown database SVRMGR> connect internal Connected. SVRMGR> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SVRMGR> Sample scripts for startup/shutdown Oracle database and listener process. $ id uid=404(orasys) gid=400(dba) groups=405(oinstall) $ $ ls -l total 3 -rwxr-x--- 1 orasys dba 298 Apr 13 20:40 SxxOracle.sh -rwx------ 1 orasys dba 146 Apr 13 20:38 dbstart.sh -rwx------ 1 orasys dba 158 Apr 13 20:38 dbstop.sh $ The owner for each unix shell file must be oracle owner and have right to execute. This is a sample start file for startup Oracle Database. $ cat dbstart.sh #!/bin/ksh export ORACLE_HOME=/oracle/OraHome1 export ORACLE_SID=viper svrmgrl << 0xff connect internal startup exit 0xff sleep 5 lsnrctl start $ This is a sample start file for shutdown Oracle Database. $ $ cat dbstop.sh #!/bin/ksh export ORACLE_HOME=/oracle/OraHome1 export ORACLE_SID=viper lsnrctl stop sleep 5 svrmgrl << 0xff connect internal shutdown immediate exit 0xff $ Create a main script file for automatic startup and shutdown with rc program. $ cat SxxOracle.sh #!/bin/ksh # PATH=/sbin:/usr/sbin:/usr/bin export PATH export ORACLE_HOME=/oracle/OraHome1 case "$1" in 'start') su - orasys -c '$ORACLE_HOME/scripts/dbstart.sh' & ;; 'stop') su - orasys -c '$ORACLE_HOME/scripts/dbstop.sh' & ;; *) echo "usage: $0 {start|stop}" ;; esac $ A Shell Script To Take RMAN Cold,Hot and Export Backup #!/bin/bash ORACLE_SID=OTM;export ORACLE_SID echo $ORACLE_SID echo “Please Specify the kind of backup you want to take” echo “1) COLD BACKUP” echo “2) HOT BACKUP” echo “3) EXPORT BACKUP” echo “Enter your option” read option while [ $option -gt 3 ]||[ $option -le 0 ] do echo “Please Enter the correct option” read option done case $option in 1|2) echo “You are taking rman backup of DB” rman target sys/sys @/oracle/product/11g/rman_backup_$option.txt;exit;; 3) echo “You are taking export backup of DB” exp system/sys file=/oracle/exp_dat.dmp log=/oracle/exp_dat.log full=y; exit;; esac exit The above script can call anyone of the following rman script depending upon the user who wants take cold or hot backup The content of rman_backup_1.txt run { shutdown immediate; startup mount; allocate channel dup1 device type disk; allocate channel dup2 device type disk; backup format ‘/oracle/%U’ database; release channel dup1; release channel dup2; alter database open; } The content of rman_backup_2.txt run { allocate channel dup1 device type disk; allocate channel dup2 device type disk; backup format ‘/oracle/%U’ database; backup format ‘/oracle/arch_%U’ archivelog all; backup format ‘/oracle/ctl_%U’ current controlfile; release channel dup1; release channel dup2; } RMAN backup script – example – logging output Posted by John Hallas on March 20, 2008 To answer a question about writing the output from RMAN commands to a logfile I posted a copy of a shell script I use to the Oracle-L newsgroup. It is a script I use for testing which does explain the multiple RMAN commands, much of which are commented out. I #!/bin/ksh export ORACLE_HOME=/u00/app/oracle/product/11.1.0/db_2 export ORACLE_SID=TEST1 export PATH=$PATH:$ORACLE_HOME/bin export NLS_DATE_FORMAT=’DD-MON-YY HH24:MI:SS’ export DATE=$(date +%Y-%m-%d) rman target backup_admin/xxxxxxx catalog rman/xxxxxxx@server msglog /export/backups/rman/11g/logs/rman_full_backup_db_online_TEST1_${DATE}.log <<EOF #backup AS COMPRESSED BACKUPSET database ; #backup AS COMPRESSED BACKUPSET archivelog all delete input ; backup AS COMPRESSED BACKUPSET database plus archivelog delete input; #backup AS COMPRESSED BACKUPSET database; #backup database; #backup archivelog all delete input; #BACKUP INCREMENTAL LEVEL 0 TAG = WEEKLY DATABASE; #delete noprompt force obsolete; #Change archivelog all validate exit; EOF exit From the Oracle documentation I also found the following notes Using RMAN with Command Files A command file is a text file which contains RMAN commands as you would enter them at the command line. You can run the a command file by specifying its name on the command line. The contents of the command file will be interpreted as if entered at the command line. If the LOG command line argument is specified, RMAN directs output to the named log file. Command files are one way to automate scheduled backups through an operating system job control facility. In this example, a sample RMAN script is placed into a command file called commandfile.rcv. You can run this file from the operating system command line and write the output into the log file outfile.txt as follows: % rman TARGET / CATALOG rman/cat@catdb CMDFILE commandfile.rcv LOG outfile.txt Directing RMAN Output to a Log File When you run RMAN in command line mode, it sends the output to the terminal. If you specify the LOG option, then RMAN writes the output to a specified log file instead. Output for currently executing RMAN jobs is also stored in the V$RMAN_OUTPUT view, which reads only from memory (that is, the information is not stored in the control file). The V$RMAN_STATUS view contains metadata about jobs in progress as well as completed jobs. The metadata for completed jobs is stored in the control file. Question: I need to automate a script that allows me to sign-on to RMAN via a batch script. I can easily sign-on to SQL*Plus as SYSDBA but I cannot use the same syntax with RMAN. Answer: The trick for signing-on to the RMAN command interpreter is to use the following set-up for the environment and commands. You can use bash, ksh, csh or sh. Also see these related RMAN scripts, including RMAN backup scripts from Windows DOS scripts for RMAN automated backups. Here is yet another RMAN script that will monitor the progress of your RMAN script. #!/bin/sh . /u01/app/oracle/.profile1 ${ORACLE_HOME}/bin/rman <<EOF connect target sys/syspassword@cricprod_prim connect auxiliary sys/syspassword@cricprod_logstdby show all; EOF Scheduling Jobs with crontab Linux Tips by Burleson Consulting The cron Daemon This final chapter will introduce the details on how to schedule shell scripts to execute on a regular timetable. The cron daemon is the system task that runs scripted jobs on a pre-determined schedule. The crontab command is used to tell the cron daemon what jobs the user wants to run and when to run those jobs. Each Linux user can have their own crontab file, if allowed by the System Administrator. The administrator controls use of crontab by including users in the cron.deny file to disallow use of crontab. crontab Options As shown in Table 10.1, the crontab command has several options with different purposes. Option Purpose -e edit the current crontab file using the text editor specified by the EDITOR environment variable or the VISUAL environment variable -l list the current crontab file -r remove the current crontab file -u specifys the user’s crontab to be manipulated. This is usually used by root to manipulate the crontab of other users or can be used by you to correctly identify the crontab to be manipulated if you have used the su command to assume another identity. Table 10.1: crontab options and purposes crontab also accepts a file name and will use the specified file to create the crontab file. Many users prefer to use this option rather than the crontab -e command because it provides a master file from which the crontab is built, thus providing a backup to the crontab. The following example specifies a file called mycron.tab to be used as the input for crontab. $ crontab mycron.tab Here's how you would use the crontab –l command to view the current cron entries for the logged in user. $ crontab -l #********************************************************** # Run the Weekly file cleanup task at 6:00AM every Monday # and send any output to a file called cleanup.lst in the # /tmp directory #********************************************************** 00 06 * * 1 /home/terry/cleanup.ksh > /tmp/cleanup.lst #********************************************************** # Run the Weekly Management Report every Monday at 7:00 AM # and save a copy of the report in my /home directory #********************************************************** 00 07 * * 1 /home/terry/weekly_mgmt_rpt.ksh wprd > /home/terry/weekly_mgmt_rpt.lst Now if we wanted to delete all the entries in the crontab we can use the –r option. $ crontab -r The Format of the crontab File The crontab file consists of a series of entries specifying what shell scripts to run and when to run it. It is also possible to document crontab entries with comments. Lines which have a pound sign (#) as the first non-blank character are considered comments. Blank lines are completely ignored. Comments cannot be specified on the same line as cron command lines. Comments must be kept on their own lines within the crontab. There are two types of command lines that can be specified in the crontab: environment variable settings and cron commands. The following sections will provide more detail on these two types of crontab entries. Environment variable settings Each environment variable line consists of a variable name, an equal sign (=), and a value. Values that contain spaces need to be enclosed within quotes. The following are some examples of environment variable settings: color = red title = ‘My Life in a Nutshell’ It is important to remember that variable names are case sensitive and that system variables are usually defined with upper case names, while user defined variables are defined with lower case names. crontab Command Lines Each crontab command line is comprised of six positional fields specifying the time, date and shell script or command to be run. The format of the crontab command line is described in Table 10.2 below: Field Valid values Minute 0-59 Hour 0-23 Day of Month 1-31 Month 1-12 Day of Week 0-7 Command Command path/command Table 10.2: crontab command line format Each of these fields can contain a single number, a range of numbers indicated with a hyphen (such as 24), a list of specific values separated by commas (like 2,3,4) or a combination of these designations separated by commas (such as 1,3-5). Any of these fields may also contain an asterisk (*) indicating every possible value of this field. This can all get rather confusing so let's take a look at a few examples. The next several examples are all part of the same crontab file. We have broken it up in order to explain each entry individually. # Use the Korn Shell for all shell scripts SHELL=/bin/ksh This sets the default shell for these cron scripts by setting the SHELL environment variable. #********************************************************** # Run the Weekly file cleanup task at 6:00AM every Monday # and send any output to a file called cleanup.lst in the # /tmp directory #********************************************************** 00 06 * * 1 /home/terry/cleanup.ksh > /tmp/cleanup.lst This entry will run the script cleanup.ksh at 0 minutes past the hour, 6 am, every day of the month, every month of the year, but only on Mondays. This illustrates that for a crontab to execute all of the conditions specified must be met, so even though we've said every day of the month by making the third field a wildcard, the day also has to meet the final condition that the day is a Monday. #********************************************************** # Run the Weekly Management Report every Monday at 7:00 AM # and save a copy of the report in my /home directory #********************************************************** 00 07 * * 1 /home/terry/weekly_mgmt_rpt.ksh wprd > /home/terry/weekly_mgmt_rpt.lst This entry is very similar but will execute at 7:00am. Since the hour is in 24 hour format (midnight is actually represented as 00) we know the 07 represents 7:00 a.m. This entry again will only be run once a week. #********************************************************** # Weekly Full Backup - run every Sunday at 1:30AM #********************************************************** 30 01 * * 0 /home/terry/full_backup.ksh wprd > /tmp/full_backup.lst Here we have specified this script to be run at 30 minutes past the hour, the first hour of the day, but only on Sundays. Remember that in the day of the week column Sunday can be represented by either 0 or 7. #********************************************************** # Nightly Incremental Backup - run Monday-Saturday at 1:30AM #********************************************************** 30 01 * * 1-6 /home/terry/incr_backup.ksh > /tmp/incr_backup.lst In this crontab entry we see the same indication for hour and minute as the last entry but we have specified a range for the day of the week. The range 1-6 will cause the incr_backup.ksh to be executed at 1:30 every morning from Monday through Saturday. #********************************************************** # Low disk space alert ... run every 15 minutes, sending # alerts to key individuals via e-mail #********************************************************** 00,15,30,45 * * * * /home/terry/free_space.ksh > /tmp/free_space.lst This entry has minutes separated by a comma indicating that it should be run at each of the indicated times. Since all the other fields are wildcards (*) the entry will be run on the hour (00), 15 minutes past the hour, 30 minutes past the hour and 45 minutes past the hour. #********************************************************** # Lunch Time Notification - run Monday-Friday at Noon # sends a message to all users indicating it's lunch time #********************************************************** 00 12 * * 1-5 /home/terry/lunch_time.ksh wprd > /tmp/lunch_time.lst This lunch reminder is set up to run at 12:00 p.m. Monday through Friday only. The most important thing to remember is that a crontab entry will execute every time all of its conditions are met. To take the last entry as an example, any time it is 00 minutes past the hour of 12 on any day of the month and any month of the year and the day of the week is between Monday and Friday inclusive (1-5) this crontab will be executed. You will use wildcards in most crontab entries but be careful where you use them. For instance, if we mistakenly placed a * in the minute position of the last crontab example above we would end up running the script for ever minute of the 12:00 hour instead of just once at the beginning of the hour. I don't think anyone needs that many reminders to go to lunch, do you? As mentioned above, the day-of-week field accepts either zero or seven as a value for Sunday. Any of the time/date fields can also contain an asterisk (*) indicating the entire range of values. Additionally, month and day-of-week fields can contain name values, consisting of the first three letters of the month, as indicated in Table 10.3 below. Field Valid Entries (case insensitive) Days of the week sun, mon, tue, wed, thu, fri, sat SUN, MON, TUE, WED, THU, FRI, SAT Months of year jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC When numbers are used, the user can specify a range of values separated by a hyphen or a list of values separated by commas. In other words, specifying 2-5 in the hour field means 2AM, 3AM, 4AM and 5AM, while specifying 2,5 means only 2AM and 5AM. We've talked an awful lot about how to specify the date and time in the crontab but what about the command? Well, most folks will write shell scripts to execute with their crontab entries but you can actually just execute a command from the crontab as well. Either way make sure you put the absolute path to your command in the crontab. If the command or script you call in your crontab typically sends output to the screen you will probably want to redirect that output to a log file with the >> symbol so you can check it later. Be careful with this as the log files may get rather large over time! Shell Script for RMAN Backup Few days back i devoted my time in creating a shell script to take RMAN backup for a 2-node RAC database on Sun Solaris.Both the datafiles and the archive logfiles(for both the instances) are on a shared SAN box. Below is the script :ORACLE_HOME=/projects/product/10.2.0/db_1 export ORACLE_HOME ORACLE_SID=test1 export ORACLE_SID PATH=$PATH:$ORACLE_HOME/bin export PATH set -x RMAN_BACKUP=/projects/test_backup Rman_Log=$RMAN_BACKUP/"$ORACLE_SID"_backup_log touch $Rman_Log echo "\n\n ****RMAN FULL BACKUP****" >> $Rman_Log echo "\n rman full startup time: `date`" >> $Rman_Log DD=`date +%d%m%y` mkdir /backup/rman/datafiles_backup/bkp_${DD} mkdir /backup/rman/controlfile_backup/bkp_${DD} mkdir /backup/rman/arch_backup/bkp_${DD} sqlplus -s "sys/xxxxxx@TEST1 as sysdba" <<EOF >> $Rman_Log set feedback off; alter system archive log current / set serveroutput on declare x number; y number; begin select max(SEQUENCE#) into x from gv\$archived_log where thread#=1; dbms_output.put_line('The Strat Sequence number on instance 1 = '||x||''); sys.dbms_system.ksdwrt(2,'Note to DBA : On Instance 1 RMAN Backup Starts at '||to_char(x)||' on '||to_char(sysdate,'DD/MON/YYYY HH:MM:MI')); select max(SEQUENCE#) into y from gv\$archived_log where thread#=2; dbms_output.put_line('The Strat Sequence number on instance 2 = '||y||''); sys.dbms_system.ksdwrt(2,'Note to DBA : On Instance 2 RMAN Backup Starts at '||to_char(y)||' on '||to_char(sysdate,'DD/MON/YYYY HH:MM:MI')); end; / exit EOF rman target / nocatalog log=$RMAN_BACKUP/rman_fullbackup_${DD}.log << EOF1 change archivelog all crosscheck; run { CONFIGURE RETENTION POLICY TO REDUNDANCY 1; CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET; backup as compressed backupset incremental level 0 database tag 'TEST_FULL_BACKUP' format '/backup/rman/datafiles_backup/bkp_${DD}/%d_%s_%p'; backup as compressed backupset archivelog all not backed up 1 times FORMAT '/backup/rman/arch_backup/bkp_${DD}/ARCH_%d_%s_%p'; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/ora_backup/rman/controlfile_backup/bkp_${DD}/%F'; delete noprompt obsolete; delete noprompt archivelog all completed before 'sysdate-2'; } EXIT; EOF1 sqlplus -s "sys/xxxxxxx@TEST1 as sysdba" <<EOF2 >> $Rman_Log set feedback off; alter system archive log current / set serveroutput on declare x number; y number; begin select max(SEQUENCE#+1) into x from gv\$archived_log where thread#=1; dbms_output.put_line('The Finished Sequence number on instance 1 = '||x||''); sys.dbms_system.ksdwrt(2,'Note to DBA : On Instance 1 RMAN Backup Finished at '||to_char(x)||' on '||to_char(sysdate,'DD/MON/YYYY HH:MM:MI')); select max(SEQUENCE#+1) into y from gv\$archived_log where thread#=2; dbms_output.put_line('The Finished Sequence number on instance 2 = '||y||''); sys.dbms_system.ksdwrt(2,'Note to DBA : On Instance 2 RMAN Backup Finished at '||to_char(y)||' on '||to_char(sysdate,'DD/MON/YYYY HH:MM:MI')); end; / exit EOF2 echo "\n rman fullbackup end time: `date`" >> $Rman_Log Some Features:- 1. Two log files will be generated.One with the name “$ORACLE_SID_backup_log” and the other with “rman_fullbackup_${DD}.log” (DD will be the current date).The first log file ($ORACLE_SID_backup_log) will have the a. The startup time of the script run b. The maximum archive log sequence number – before the start of the backup and after the end of the backup c. The end time of the backup. The rman_fullbackp_${DD} will look like rman_fullbackp_030310,if run on 03rd March 2010.Every time the script runs it will generate a new logfile.It will contain the details of the RUN block in RMAN backup. 2. A line in the alert log of both the instances ,with the maximum sequence number (before the start of the backup and after the end of the backup) will be written.For example Note to DBA : On Instance 2 RMAN Backup Starts at 2289 on 03/03/2010 02:40:00 3. All the archivelogs will be backed up as “NOT BACKED UP 1 TIMES” is being used.Even if the crontab didn’t run a particular day or time , the next time it runs it will take the backup of all those archivelogs that haven’t been backed up even once. 4. The backup pieces goes to the current date folder which is created using mkdir /backup/rman/datafiles_backup/bkp_${DD} Suppose the backup is run on 03rd March 2010, so it will create a folder bkp_030310 inside “/backup/rman/datafiles_backup” and place all the backup pieces inside it.Similar is the case for archivelogs and the controlfile. 5. The retention and the deletion policy varies as per the requirements .I take a full backups on Sunday and rest all the days its incremental, with the same script with few modifications and the most important one is backup as compressed backupset incremental level 1 database Hope this helps someone and as always, suggestions are welcomed. > Hello, > I am trying to run the RMAN backup from a script (unix). i wrote a > small script (sh) with following commands: > rman TARGET / > RUN { backup database; >} > when i run it gives errors RUN, backup commands not found. Who gives errors? Your shell? If what you posted is taken from your script exactly, shell should never get control after rman was called (except , rman command was not found) .. If it is rman, could you post the entire error stack and some unimportant details such as Oracle version and OS ? > Do i need to store this file under some specific dir? am i missing > something? > Thanks > In general, to run rman from shell script you have to ensure, that you have proper environment set (on Linux it may be necessary to get rid of another rman executable which has nothing to do with oracle). The next thing, you have to redirect somehow the contents of your shell script to rman input. It can be for example a here document or somewhat else... #! /bin/bash ORACLE_HOME=/abc/xyz PATH=$ORACLE_HOME/bin:$PATH ORACLE_SID=yoursid export ORACLE_HOME ORACLE_SID PATH rman target / << RMAN_SCRIPT > backup.log backup database; exit; RMAN_SCRIPT exit 0 Best regards Maxim