×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

script to zip and tar files at once.

script to zip and tar files at once.

script to zip and tar files at once.

(OP)
hello All,

I have this in my /etc/oratab
dbase1:/orahome/app/oracle/product/11.2.04/dbbase:N
dbase2:/orahome/app/oracle/product/10.2.05/dbbase:N

The idea is to use a script to loop through each database, mindful that Database HOME is different.
Again, go into directory:
/orahome/app/oracle/admin/dbase1/adump
or
/orahome/app/oracle/admin/dbase2/adump
1) remove all files older than 7 days including old zip and tar files.
2) zip and tar the rest of the files while renaming it and put a timestamp of the day of creation of tarball.

Here is my script
#!/bin/ksh
#
# Script Name: copy_zip_tar.sh
#

ORACLE_SID=`cat /etc/oratab | grep -v "^#" | grep -v "^\*" | grep -v "^agent" | cut -d":" -f1 | sort`
while read ORACLE_SID
do
find /orahome/app/oracle/admin/'$ORACLE_SID'/adump/* -mtime +7 -exec rm{} \
tar cvf /orahome/app/oracle/admin/'$ORACLE_SID'/adump/*aud | gzip -c > '$ORACLE_SID'_aud_files`date +" %b_%d_%Y"`.tar.gz
done
exit

Above is my effort.
I have to admit that I have not tested this.
Please help & thanks for your help in advance.

RE: script to zip and tar files at once.

Couple little things wrong. The 'f' parameter to 'tar' will be looking for a filename to create. It won't do what you're wanting it to do. A dash will send its output to the pipeline.

Try this...

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
#  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
done

exit 

I changed your date format to something that will stay sorted chronologically in a directory listing ("YYYYMMDD"). Sorry, but the format you had is a pet peeve of mine. Change it back if you want/need to.

RE: script to zip and tar files at once.

Oops, sorry, your 'find' command needs some help too. I tried to edit my post, but got an error. I'll add it here.

The first parameter of a 'find' should be a directory. It should look more like this...

CODE

find /orahome/app/oracle/admin/${ORA_SID}/adump  -mtime +7 -exec rm {} \; 

And as before, you can use a '-ls' to just list the file before testing instead of actually deleting them.

RE: script to zip and tar files at once.

(OP)
Thanks Sam Bones

RE: script to zip and tar files at once.

FWIW - instead of piping the output to the gzip command why not simply specify tar's -g option which will output a gzipped format file directly?

ex: tar -cgf ./mytarfile.gz files_to_include

Just saves keystrokes and exec time. My 2 cents worth.

RE: script to zip and tar files at once.

Excellent suggestion. Just confirm that your 'tar' has the -g option. Some don't.

RE: script to zip and tar files at once.

(OP)
Hello BobMCT & SamBones,

Thanks for your inputs.

However, the requirements have changed a little bit:

In addition, the will like to add the following:
1) On the first day of each month, zip and create a tar file from existing *aud files.
2) Everyday thereafter, compress new *aud files and append it to the to the existing tar file created in (1).


fmonth=`date '+%d'`
if [ $fmonth == 01 ]
do
tar -cgf /orahome/app/oracle/admin/${ORA_SID}/adump/{ORA_SID}_aud_files_$(date '+%B%Y').tar.gz /orahome/app/oracle/admin/${ORA_SID}/adump/*aud
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
fi

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close