Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any input will be "YUGELLY" appreciated!!

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
CA
Hello All,
Plase your additional input will be "YUGELLY" appreciated :)

Requirements:
1) On the first day of each month, zip and create a tar file from existing *aud files.
2) On everyday thereafter, compress new *aud files and append it to the to the existing tar file created in (1).


#!/bin/ksh
#ScriptName:copy_zip_tar.sh

#SetInter-FieldSeparatortocolon.Simplifiesparsingtheinputfile.
IFS=:

cat/etc/oratab|whilereadORA_SIDORA_HOMEORA_START

fmonth=`date'+%d'`

if[$fmonth==01]
do
#find/orahome/app/oracle/admin/${ORA_SID}/adump-mtime+7-execrm{}\;
#candothefollowingfortesting...
find/orahome/app/oracle/admin/${ORA_SID}/adump/*-mtime+7-ls

tar cvf-/orahome/app/oracle/admin/${ORA_SID}/adump/*aud|gzip-c > ${ORA_SID}_aud_files_$(date'+%Y%m%d').tar.gz
else
tar cvf-/orahome/app/oracle/admin/${ORA_SID}/adump/*aud|gzip-c > /orahome/app/oracle/admin/${ORA_SID}/adump/{ORA_SID}_aud_files_$(date'+%B%Y').tar.gz
done
exit
 
Hello, I will really apreciate your input, the code as written below is giving me error:

/copy_zip_tar.sh[7]: syntax error at line 19 : `else' unexpected

Code:
#! /bin/ksh
# Script Name: copy_zip_tar.sh

# Set Inter-Field Separator to colon. Simplifies parsing the input file.
IFS=:

cat /etc/oratab | while read ORA_SID ORA_HOME ORA_START

fmonth=`date '+%d'`

if [ $fmonth == 01 ]
{
#  find /orahome/app/oracle/admin/${ORA_SID}/adump  -mtime +7 -exec rm {} \;
# can do the following for testing...
  find /orahome/app/oracle/admin/${ORA_SID}/adump/* -mtime +7 -ls

  tar cvf - /orahome/app/oracle/admin/${ORA_SID}/adump/*aud | gzip -c > ${ORA_SID}_aud_files_$(date '+%Y%m%d').tar.gz
else
   tar cvf - /orahome/app/oracle/admin/${ORA_SID}/adump/*aud | gzip -c > /orahome/app/oracle/admin/${ORA_SID}/adump/{ORA_SID}_aud_file
s_$(date '+%B%Y').tar.gz
}
fi
exit
 
Below is the modified version.
Question - is this the correct best practices?
Given the requirement:
1) On the first day of each month, zip and create a tar file from existing *aud files.
2) On everyday thereafter, compress new *aud files and append it to the to the existing tar file created in (1).


Code:
#! /bin/ksh
# Script Name: copy_zip_tar.sh

# Set Inter-Field Separator to colon. Simplifies parsing the input file.
IFS=:

cat /etc/oratab | while read ORA_SID ORA_HOME ORA_START
do
fmonth=`date '+%d'`

if [ $fmonth == 01 ]
then
#  find /orahome/app/oracle/admin/${ORA_SID}/adump  -mtime +7 -exec rm {} \;
# can do the following for testing...
  find /orahome/app/oracle/admin/${ORA_SID}/adump/* -mtime +7 -ls

  tar cvf - /orahome/app/oracle/admin/${ORA_SID}/adump/*aud | gzip -c > ${ORA_SID}_aud_files_$(date '+
%Y%m%d').tar.gz
else
   tar cvf - /orahome/app/oracle/admin/${ORA_SID}/adump/*aud | gzip -c > /orahome/app/oracle/admin/${O
RA_SID}/adump/{ORA_SID}_aud_files_$(date '+%B%Y').tar.gz
fi
done
exit
 
So does it work now?
As to the best practices, everyone chooses what works best for the task at hand. If it efficiently does what you need, is easy to maintain and meets your company standards, that should do.
I would consider using variables in place of long directory names having assigned these at the top of the script, and using ${long_var_name} instead of $long_var_name notation.
 
Question - is this the correct best practices?
Given the requirement:
1) On the first day of each month, zip and create a tar file from existing *aud files.
2) On everyday thereafter, compress new *aud files and append it to the to the existing tar file created in (1).

There isn't a particularly "global" best practice, just what suits your requirement the best.

Personally for my email backup (Done weekly), I update a tar Sunday through to Friday then update, compress then archive on the Saturday, rename the previous week's tar and create a new tar.

update the tar
Code:
tar -uf archive.tar folder-name/
( Sunday - Friday)

Final update then compress the tar and date and relocate it. (Saturday)

Code:
# update
  tar -uf archive.tar folder-name/ 
# compress
  gzip archive.tar
# set date and archive
  DATE=$(date +%Y%m%d)
  mv archive.tar.gz archive/$DATE.tar.gz
# backup current week
  mv archive.tar archive.old.tar
# create new
  tar -cf archive.tar folder-name/



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top