...
a. Logon as root.
No Format |
---|
su - |
change directory to /usr/local/bin
No Format |
---|
cd /usr/local/bin |
b. Download the b. Create an archive management script from the dbvisit.com website named del_arch.sh that will manage the archives.
No Format |
---|
[root@source bin]# wget http://ww2.dbvisit.com/download/files/external/del_arch.sh
--2013-12-23 01:13:17-- http://ww2.dbvisit.com/download/files/external/del_arch.sh
Resolving ww2.dbvisit.com... 67.222.54.241
Connecting to ww2.dbvisit.com|67.222.54.241|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1822 (1.8K) [application/x-sh]
Saving to: `del_arch.sh'
100%[================================================================================================================>] 1,822 --.-K/s in 0s
2013-12-23 01:13:18 (104 MB/s) - `del_arch.sh' saved [1822/1822] |
...
vi /usr/local/bin/del_arch.sh |
c. Paste the following contents and save and exit the script (:wq!).
No Format |
---|
#!/bin/bash
#
# set -x
###########################################
# Function to echo usage
###########################################
usage ()
{
echo
echo "Usage: del_arch <dbsid> <retention_in_days>"
echo example: del_arch testdb 0.5
echo
echo Default retention is 2 days
}
###########################################
# Function to setup parameter variables
###########################################
setup_parameters ()
{
system_hostname=`uname -n`
program_name=`basename $0`
dba_top=/u01/oracle/log
log=${dba_top}/rman_${db}-`date +%d%m%Y%H%M`.log
[ -d "${dba_top}" ] || mkdir ${dba_top}
}
###########################################
# Function to change database environments
###########################################
change_db ()
{
export ORAENV_ASK=NO
export ORACLE_SID=$1
. /usr/local/bin/oraenv >> /dev/null
}
###########################################
# Function to Add text to logfile
###########################################
addLog()
{
echo "`date +%d-%h-%Y:%H:%M:%S` : $1" >> ${log}
}
###################################
# Function to purge archive logs #
###################################
run_delete ()
{
change_db ${db}
addLog "Start Delete with rentention ${retention}..."
echo "Start Delete with rentention ${retention}..."
rman append msglog=${log} <<!EOF
connect target /
run {
change archivelog all validate;
delete noprompt archivelog until time 'SYSDATE-${retention}';
}
!EOF
addLog "End Delete..."
}
##################
##### Main Program
##################
db=$1
PATH=$PATH:/usr/local/bin/:.
export TMP=/u03/tmp
retention=$2
if [ -z "$retention" ]
then
retention=2
fi
if [ -z "$db" ]
then
usage
exit 2
else
setup_parameters
change_db ${db}
run_delete
fi |
d. Make the script executable and change ownership to oracle.
...
No Format |
---|
[root@source bin]# exit |
de. As user oracle, add the script to the oracle crontab.
No Format |
---|
su - oracle |
No Format |
---|
crontab -e |
ef. Add the following line to crontab and then save and exit (:wq) This runs the script every 15 minutes and deletes all archives older than 4.8 hours (0.2 days).
...