SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Automatically save and circulate the offline redos (SH)



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Connect to External system, Unix и Perl
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Nov 17, 2007 10:30 pm    Post subject: Automatically save and circulate the offline redos (SH) Reply with quote

Automatically save and circulate the offline redos to a remote server - local script

Code:
#!/bin/ksh
##############################################################################
#  File Name:     double_archieve.sh
#
#  Usage:         Run it from crontab 6 times an hour:
#
#  su - SIDadm -c "/sapglobal/SHELL/ARCHIVE/doublearchive.sh" >/dev/null 2>&1
#
#  Description:  Usually the weekly backup tapes are transferred to a remote
#                site, but the current offline redo logs are not. In case of a
#                local disaster, rolling forward becomes impossibble, because
#                both the database and the locally stored tapes get destroyed.
#                This script provides a protection against this situation
#                by automatically sending to and circulating the archive logs
#                on a remote machine.
#                This script runs on the local machine. It archives the offline
#                redos locally and sends them to the remote machine as well.
#                After sucessfuly archiving and copying them, it deletes
#                the redo logs. Once a day it removes the old local brarchive
#                logs too.
#
#  Dependencies: Requires brarchive V4.5
#                SIDadm has to exist on the remote host
#                The local SIDadm has to be a trusted user on the remote machine
#                A second brarchive par. file is needed for the remote copy on
#                the local machine containing:
#
#                archive_copy_dir = /oracle/SID/saparch
#                remote_host = remote_host_name                 
############################################################################## 
sid=SID
ORACLE_SID=$sid;export ORACLE_SID
ORACLE_HOME=/oracle/$sid;export ORACLE_HOME
#
brarchive=/sapmnt/$sid/exe/brarchive
prof=/oracle/$sid/dbs/remotecopy.sap
pwd=system/dbajan
tlog=/sapglobal/LOG/ARCHIVE/temp_log
plog=/sapglobal/LOG/ARCHIVE/permanent_log
lockfile=/sapglobal/LOG/ARCHIVE/doublearchive_lockfile
pat=successfully
#
hour_minute=`date "+%H%M"`
cleanup_time=1200
brarchive_log_dir=$ORACLE_HOME/saparch
remove_dayold=2
#
# Handle the signals
#
trap "clean_and_exit" 1 2 3 15 25
clean_and_exit ()
{
  rm -f $lockfile
  echo "Interrupt signal received - exiting" >> $plog
  exit 0
}       
#
# Check if another instance of double_archive is running
#
if [ -f $lockfile ]; then
   echo "Already running - exiting" >> $plog
   exit 0
fi
touch $lockfile
#
date >> $plog
#
# Archive the archive logs
#
a=`$brarchive -d disk -s -c -u $pwd|tee $tlog|grep $pat`
if [ "$a" = "" ] ; then
   echo Failed to stop archive the remaining files, exiting >> $plog
   rm -f $lockfile
   exit 0
else
   cat $tlog|grep "#SAVED"|awk '{printf(" Local archiving:%s\n",$2)}' >> $plog
fi
#
# Copy the archive logs to the remote machine
#
a=`$brarchive -d stage -s -c -u $pwd -p $prof|tee $tlog|grep $pat`
if [ "$a" = "" ] ; then
   echo Failed to copy the arhive files to the remote machine, exiting >> $plog
   rm -f $lockfile
   exit 0
else
   cat $tlog|grep "#SAVED"|awk '{printf(" Remote copy:    %s\n",$2)}' >> $plog
fi
#
# Remove the archive logs that has been  sucessfully archived and copied
#
a=`$brarchive -d disk -ds -c -u $pwd|tee $tlog|grep $pat`
if [ "$a" = "" ] ; then
   echo Failed to delete the double saved archive logs, exiting >> $plog
   rm -f $lockfile
   exit 0
else
   cat $tlog|grep BR015I|awk '{printf(" Deleting:       %s\n",$6)}' >> $plog
fi
#
# Once a day remove the old brbackup log files
#
if [ $hour_minute = $cleanup_time ]; then
  echo Removing the old brarchive log files >> $plog
  find $brarchive_log_dir -name "*.dsv" -ctime +$remove_dayold -exec rm -f {} \;
  find $brarchive_log_dir -name "*.sve" -ctime +$remove_dayold -exec rm -f {} \;
  find $brarchive_log_dir -name "*.fst" -ctime +$remove_dayold -exec rm -f {} \;
fi
#
rm -f $lockfile


The remote script

Code:
#!/bin/ksh
###############################################################################
#  File Name:     recycle_archivelog.sh
#
#  Usage:        Run it once an hour on the remote machine from crontab
#
#  Description:  Compresses the uncompressed archive log files (except for the
#                newest one - the file transfer may not have been completed)
#                Removes archive logs older than the retention period
#                Alerts sysadmin, when the free space in the archive filesystem
#                drops under the threshold
############################################################################### 
#
retention_per=14
arch_dir=/oracle/SID/saparch
fs=/oracle/SID
threshold=90
#
# Compress all the archive logs but the newest (it may not be complete)
#
newnum=`ls -lt $arch_dir/*.dbf|wc -l`
if [ $newnum -gt 1 ]; then
   newest=`ls -lt $arch_dir/*.dbf|head -2|tail -1|awk '{print $9}'`
        find $arch_dir -name "*.dbf" ! -newer $newest -exec compress {} \;
fi
#
# Remove the archive logs older then retention_per
#
find $arch_dir -name "*.dbf.Z" -mtime +$retention_per -exec rm -f {} \;
#
# Alert sysadmin, if the free space drops under the threshold
#
used_perc=`bdf|grep $fs|grep -v $fs/|awk '{print $5}'|awk -F\% '{print $1}'`
if [ $used_perc -gt $threshold ]; then
# Run your own paging scripts here
fi
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Connect to External system, Unix и Perl All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.