This post will show a backup script used to create copies for a server running Oracle 10.2, some application server like FourJS and JBoss and some custom application written in java.
The backup process is divided in some parts :
- Variable declaration and export
- Oracle export and compress
- Data folder export and compress
- Application Server export and compress
- Tape writing of all compress file
- Tape checking
- Mail logging
This post assume you have the following enviroments, if you have something different you should only change variable declaration and comment some lines to have this script works.
- Oracle SID : DB01
- Oracle main folder : /oracle/product/10.2/db_1
- Oracle user/password : system/system
- DATA main folder to backup : /data
- APPSERVER main Folder : /appsrv
- Main backup folder : /data/backup
- Tape device : /dev/st0
#!/bin/sh
#
# Backup script created by Riccardo Riva
#NLS_LANG=ITALIAN_ITALY.WE8ISO8859P1; export NLS_LANG
NLS_DATE_FORMAT=dd/mm/yyyy; export NLS_DATE_FORMAT
NLS_NUMERIC_CHARACTERS=,.; export NLS_NUMERIC_CHARACTERS
ORACLE_HOME=/oracle/product/10.2/db_1; export ORACLE_HOME
ORACLE_SID=DB01; export ORACLE_SID
ORACLE_USERID=system/system; export ORACLE_USERID
DATA=/data; export DATA
APPSRV=/appsrv; export APPSRV
BACKUP_BASE=/data/backup; export BACKUP_BASE
PATH=$PATH:$ORACLE_HOME/bin; export PATH
ORACLE_EXP=$BACKUP_BASE/$ORACLE_SID.exp; export ORACLE_EXP
DATA_EXP=$BACKUP_BASE/data.tgz export DATA_EXP
APPSRV_EXP=$BACKUP_BASE/appsrv.tgz export APPSRV_EXP
LOG_BASE=$BACKUP_BASE/log; export LOG_BASE
LOG=$LOG_BASE/backup.log; export LOG
LOG_ORACLE=$LOG_BASE/ora.log; export LOG_ORACLE
LOG_TMP=$LOG_BASE/tmp; export LOG_TMP
LOG_HISTORY=$LOG_BASE/history.log; export LOG_HISTORY
TAPEDEV=/dev/st0; export TAPEDEV
MT=/usr/bin/mt; export MT
ADMIN_MAIL=you@yourdomain.com; export ADMIN_MAIL# Define a DATE function to put in the log
DATE ()
{
date +”%d-%m-%Y %H:%M:%S\t”
}# Define a SHORT DATE function to use in the mail report
DATE_SHORT ()
{
date +”%d-%m-%Y”
}
# End define DATE# Clear old logs
rm -rf $ORACLE_EXP >/dev/null 2>&1;
rm -rf $GPI_EXP >/dev/null 2>&1;
rm -rf $APPSRV_EXP >/dev/null 2>&1;# Put the old log file in an history log
cat $LOG >>$LOG_HISTORY;# Write in the log file the start date
printf “##############################################################\n” >$LOG;
printf “%s `DATE` Start Backup process \n” >>$LOG;
printf “#######################################################################\n” >>$LOG;printf “##############################################################\n” >>$LOG;
printf “%s `DATE` Start export Oracle instance $ORACLE_SID \n” >>$LOG;
printf “#######################################################################\n” >>$LOG;# Export of Oracle DB defined above
exp $ORACLE_USERID@$ORACLE_SID full=y file=$ORACLE_EXP log=$LOG_ORACLE consistent=y >/dev/null 2>&1;printf “##############################################################\n” >>$LOG;
printf “%s `DATE` End export Oracle instance $ORACLE_SID \n” >>$LOG;
printf “##############################################################\n” >>$LOG;# Put the Oracle export log file in the main log file
cat $LOG_ORACLE >>$LOG;
rm -rf $LOG_ORACLE >/dev/null 2>&1;printf “##############################################################\n” >>$LOG;
printf “%s `DATE` Start to compress directory $DATA \n” >>$LOG;
printf “##############################################################\n” >>$LOG;# Compress $DATA excluding $LOG_BASE from archive
tar -czvf $DATA_EXP –exclude=$LOG_BASE/* $DATA >/dev/null 2>&1;printf “##############################################################\n” >>$LOG;
printf “%s `DATE` Start to compress directory $APPSRV \n” >>$LOG;
printf “##############################################################\n” >>$LOG;# Compress $APPSRV
tar -czvf $APPSRV_EXP $APPSRV >/dev/null 2>&1;printf “##############################################################\n” >>$LOG;
printf “%s `DATE` End compress procedure \n” >>$LOG;
printf “#######################################################################\n” >>$LOG;printf “##############################################################\n” >>$LOG;
printf “%s `DATE` Start rewind tape $TAPEDEV \n” >>$LOG;
printf “#######################################################################\n” >>$LOG;# Rewinf tape
$MT -f $TAPEDEV rewind >/dev/null 2>&1;printf “##############################################################\n” >>$LOG;
printf “%s `DATE` Start writing on tape $TAPEDEV \n” >>$LOG;
printf “##############################################################\n” >>$LOG;# Write on tape all $BACKUP_BASE folder and put results in the log
tar cf $TAPEDEV –exclude=$LOG_BASE/* $BACKUP_BASE >/dev/null 2>&1;if [ $? -eq 0 ];then
printf “##############################################################\n” >>$LOG;
printf “%s `DATE` Writing on tape succesfully \n” >>$LOG;
printf “##############################################################\n” >>$LOG;else
printf “##############################################################\n” >>$LOG;
printf “%s `DATE` Writing on tape failed \n” >>$LOG;
printf “##############################################################\n” >>$LOG;fi
printf “##############################################################\n” >>$LOG;
printf “%s `DATE` End writing on tape $TAPEDEV \n” >>$LOG;
printf “##############################################################\n” >>$LOG;printf “##############################################################\n” >>$LOG;
printf “%s `DATE` Start checking tape $TAPEDEV \n” >>$LOG;
printf “##############################################################\n” >>$LOG;# Check data written on tape e put the results on the log
tar tf $TAPEDEV >>$LOG;
if [ $? -eq 0 ];thenprintf “##############################################################\n” >>$LOG;
printf “%s `DATE` Check tape successful \n” >>$LOG;
printf “##############################################################\n” >>$LOG;# Eject tape
$MT -f $TAPEDEV eject >/dev/null 2>&1;
elseprintf “##############################################################\n” >>$LOG;
printf “%s `DATE` check tape failed \n” >>$LOG;
printf “##############################################################\n” >>$LOG;fi
printf “##############################################################\n” >>$LOG;
printf “%s `DATE` End checking tape \n” >>$LOG;
printf “##############################################################\n” >>$LOG;printf “##############################################################\n” >>$LOG;
printf “%s `DATE` End Backup process \n” >>$LOG
printf “##############################################################\n” >>$LOG;
printf “\n\n” >>$LOG;# Send the backup report using mail to $ADMIN_MAIL
cat $LOG | mail -s “`uname -n` backup report for `DATE_SHORT` ” $ADMIN_MAIL
Hope this help
Bye
Riccardo
Print This Post























