Advertisement

07.21.2008 at 07:37AM PDT, ID: 23581962
[x]
Attachment Details

Can you look at this shell script and tell me where my backups are being saved?

Asked by la_colibri in IBM AIX Unix, Unix Operating Systems, Oracle Database

Can you look at this shell script and tell me where my backups are being saved? Thanks I am not knowledgeable with shell scripts and can't understand it very well.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
 
# Initialize variables. 
#
ORACLE_SID=ADCORPRD                                    # what we are backing
trace="N"                                              # for debugging
name=`whoami`
t_date=`date +'%m%d%y%H%M'`              
 
ORATAB_FILE=/etc/oratab                                # oratab file location
PATH=/bin:/etc:/usr/bin:/usr/sbin:/usr/local/bin:/home/backup/bin
 
SRC_SYSTEM=gcunx2
DST_SYSTEM=hqunx2
SCRIPT_DIR=/home/scripts/backup/hot/$ORACLE_SID
SCRIPT_DIR1=/home/scripts/notify
LOG_DIR=/home/scripts/backup/hot/$ORACLE_SID/log
LOG_FILE=/home/scripts/backup/hot/$ORACLE_SID/log/$ORACLE_SID.$t_date
 
ARCHIVE_LOG_DEST=""
 
 
########################################################################
if [ -z $SCRIPT_DIR ] ; then
   echo "SCRIPT_DIR not set, Exiting"
   exit 5
else
  if ! [ -d $SCRIPT_DIR ] ; then
    echo "SCRIPT_DIR nonexistant or Invalid. Exiting"
    exit 4
  fi
fi
 
cd $SCRIPT_DIR
 
########################################################################
# Quick sanity check to make sure we are running as oracle.
 
if [ $name != 'oracle' ] ; then
  echo "You must be oracle to run this program"
  exit 1
fi
 
########################################################################
# Make sure that the instance name exists in the oratab file to
# insure that the variables get set correctly. If not bail out now.
 
grep $ORACLE_SID $ORATAB_FILE > /dev/null
ret_val=$?
if [ $ret_val -ne 0 ] ; then                             # No Oratab entry
  echo "Invalid SID $ORACLE_SID in ORATAB,  Exiting"
  exit 4
fi
 
## Check to see that the ORACLE_SID variable contains something meaningful
if [ -z $ORACLE_SID ] ; then
  echo "Oracle SID not set or Invalid. Exiting"
  exit 5
fi
 
 
########################################################################
#
# Have oracle script set the appropriate shell variables
#
export ORAENV_ASK="NO"                                 # set oracle paths etc
. /usr/local/bin/oraenv
 
#####################################################################
# Remove stuff left over since last run.
#
rm -f errfile                                # last error file
rm -f ex_hotbackup.sql                       # last command file
 
 
#####################################################################
# Query Oracle to determine directories where things are located.
# Determine where the User Dump Files are located
# First determine where trace file is located.
 
USER_DUMP_DEST=`sqlplus -s / << EOF
set feedback off;
set echo off;
set heading off;
set pagesize 0;
select value from v\\$parameter where name = 'user_dump_dest';
quit;
EOF
`
if [ -z $USER_DUMP_DEST ] ; then
   echo "USER_DUMP_DEST not set, Exiting"
   exit 5
else
  if ! [ -d $USER_DUMP_DEST ] ; then
    echo "USER_DUMP_DEST nonexistant or Invalid. Exiting"
    exit 5
  fi
fi
 
 
#####################################################################
# Backup the current control file to trace in case we need it.
if [ $trace = 'Y' ] ; then
  echo "Creating and Backing up Trace Control file"
  read a
fi
 
sqlplus -s / << EOF
set feedback off;
set echo off;
alter database backup controlfile to trace;
quit;
EOF
> /dev/null
 
# Now move the tracefile we just created to the backup directory.
# Look in the user dump dest (where Oracle writes controlfile), and 
# find the 10 newest files and examine each to see if it is a controlfile.
# Copy the first backup controlfile to destination directory.
 
ls -1t $USER_DUMP_DEST/*.trc | head | while read t_file
do
  grep -l "CREATE CONTROLFILE DATABASE" $t_file > /dev/null  # is a ctl file?
  retval=$?
  if [ $retval -eq 1 ]; then                                 # yep, copy it
    fname=backup_controlfile.$ORACLE_SID
    mv $t_file  $SCRIPT_DIR/$fname
    rcp $SCRIPT_DIR/$fname $DST_SYSTEM:$SCRIPT_DIR/$fname
    if ! [ -s $SCRIPT_DIR/$fname ]; then
      echo "Warning: Controlfile could not be copied "
    fi
    break;
  fi
done
 
 
############################################################################
# Generate script to take each tablespace offline, and 
# back up all the datafiles that comprise the tablespace.
#
if [ $trace = 'Y' ] ; then
  echo "Generating Scriptfile for hotbackup"
  read a
fi
 
sqlplus -s / @gen_hotbackup.sql | awk -f gen_hotbackup.awk -v dest_sys=$DST_SYSTEM > ex_hotbackup.sql
 
#####################################################################
# test to see if the SQL we just created actually exists
 
if ! [ -s $SCRIPT_DIR/ex_hotbackup.sql ] ; then
  echo "Backup Script missing or 0 length. Exiting"
  exit 7
fi
 
#####################################################################
# test to see if the SQL we just created contains any errors 
 
if [ -s $SCRIPT_DIR/ex_hotbackup.sql ] ; then
  grep 'ORA-' $SCRIPT_DIR/ex_hotbackup.sql > /dev/null
  ret_val=$?
  if [ $ret_val -eq 0 ] ; then
    echo "Backup Script Contains Errors. See $SCRIPT_DIR/ex_hotbackup.sql. Exiting"
    exit 8
  fi
else
  echo "Backup Datafile missing or 0 length. Exiting"
  exit 8
fi
 
 
 
#####################################################################
# here is where the main portion of the backup gets done. Go ahead and
# run the script we just created.
 
echo "BACKUP Started at `date`" > $LOG_FILE
 
if [ $trace = 'Y' ] ; then
  echo "Executing Backup SQL"
fi
 
sqlplus -s / @$SCRIPT_DIR/ex_hotbackup.sql  >> $LOG_FILE
 
echo "BACKUP Ended at `date`" >> $LOG_FILE
 
grep 'ORA-' $LOG_FILE > /dev/null
ret_val=$?
if [ $ret_val -eq 0 ] ; then
    echo "WARNING Backup Script Contains Errors." 
    echo "See $LOG_FILE Exiting"
fi
 
#####################################################################
# Force a log switch, and then copy all but the last file to the destination
if [ $trace = 'Y' ] ; then
  echo "Forcing a log switch"
  #read a
fi
 
SWITCH=`sqlplus -s / << EOF
set feedback off;
set echo off;
set heading off;
set pagesize 0;
alter system switch logfile;
quit;
EOF
`
 
#####################################################################
# test to see if the errfile created by the script exists
if ! [ -s $SCRIPT_DIR/errfile ] ; then
  echo "Warning errfile missing or 0 length"
  exit 9
fi
 
###################################
# Notify of success if notify.good exists
#
 
ret_val=`cat errfile | awk '{ x+=$1} END{print x}'`
if [ $ret_val -eq 0 ] ; then
   SUBJ="$ORACLE_SID Hotbackup Successful"
   if [ -s $SCRIPT_DIR1/notify.good ] ; then               
    cat $LOG_FILE | sed -e '/^$/d'|mail -s "$SUBJ" `cat $SCRIPT_DIR1/notify.good`
  fi
else
   SUBJ="$ORACLE_SID Hotbackup FAILURE"
   if [ -s $SCRIPT_DIR1/notify.list ] ; then               
    echo $SUBJ | mail -s "$SUBJ" `cat $SCRIPT_DIR1/notify.list`
   fi
    cat $LOG_FILE | sed -e '/^$/d'|mail -s "$SUBJ" `cat $SCRIPT_DIR1/notify.list`
fi
 
#
#####################################################################
# Remove any log files created by this script that are older than 10 days
find $SCRIPT_DIR/log  \( -name "$ORACLE_SID.*" \) -mtime +10 -exec rm {} \;
 
exit 0
[+][-]07.21.2008 at 07:48AM PDT, ID: 22050979

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.21.2008 at 08:35AM PDT, ID: 22051468

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: IBM AIX Unix, Unix Operating Systems, Oracle Database
Sign Up Now!
Solution Provided By: schwertner
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628