** Myself
#!/usr/bin/ksh
######### DYNAMIC ENV ##############
backupdir=/backup #directory for backup database
archdir=/backup/ARCH #directory for backup archive files
keeptime=7 #Archive age
orauser=oracle #Oracle User
oraexe=/u01/oracle/product/9.2.0/bin #Execute for oracle
blog=/u01/backup.log
######### STATIC ENV ##############
tbsfile=looptbs.lst
scriptback=backup.sql
#############################################################
####### Read information tablespace and directory archive ###
su - ${orauser} -c "${oraexe}/sqlplus /nolog" << EOF
connect / as sysdba
set head off
set feedback off
set trimspool on
set pagesize 0
set line 1000
spool tbs.lst
select name from v\$tablespace where name <> 'TEMP';
spool off
spool arch.lst
archive log list
spool off
exit
EOF
####### Crop files for list tablespace ######
tmp1=`cat tbs.lst|wc -l`
tmp2=`expr $tmp1 - 4`
head -${tmp2} tbs.lst |tail +5 > $tbsfile
####### Create script backup db and archive fileles ######
echo "su - ${orauser} -c \"${oraexe}/sqlplus /nolog\" << EOF" > $scriptback
echo "connect / as sysdba" >> $scriptback
cat $tbsfile |while read line
do
echo "alter tablespace $line begin backup ;" >> $scriptback
su - ${orauser} -c "${oraexe}/sqlplus /nolog" << EOF >> $blog
connect / as sysdba
spool tbs.lst
select d.name "SQL>" from v\$tablespace t,v\$datafile d where t.ts#=d.ts# and t.name='$line';
spool off
exit
EOF
tmp3=`grep '^/' tbs.lst`
echo "Backup file" >> $blog
echo "$tmp3 to $backupdir" >> $blog
echo "..................." >> $blog
################# Backup Datafiles #############################
echo !cp -p $tmp3 $backupdir >> $scriptback
echo "alter tablespace $line end backup ;" >> $scriptback
done
################# Backup controlfile and Parameter file #############################
echo "Backup controlfile to $backupdir/control_back.ctl" >> $blog
echo "alter database backup controlfile to '$backupdir/control_back.ctl' reuse;" >> $scriptback
echo "exit" >> $scriptback
echo "EOF" >> $scriptback
echo "cp -p ${orahome}/dbs/*pfile*.ora" ${backupdir} >> $scriptback
echo "cp -p ${orahome}/network/admin/*.ora" ${backupdir} >> $scriptback
echo "-------------------------------------------------" >> $blog
echo ""
date >> $blog
ksh $scriptback >> $blog
arch=`cat arch.lst |grep "Archive destination"|awk '{print $3}'`
################# Backup archive files #############################
echo "Backup Archive files " >> $blog
echo "$arch" >> blog
cp -p $arch $archdir >> $blog
tmp5=`find $arch -mtime +${keeptime}`
################# Delete old archive files #############################
echo "" >> $blog
echo " Delete files old than ${keeptime} days" >> $blog
echo $tmp5 >> $blog
rm $tmp5
1 comments:
could you please provide me the correct steps for runing this script, after creating tbs.lst and arch.lst, it is not start with backup process.
Amit
Post a Comment