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.
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.
Try this...
CODE
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.
The first parameter of a 'find' should be a directory. It should look more like this...
CODE
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.
RE: script to zip and tar files at once.
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.
RE: script to zip and tar files at once.
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