Export, Archiving, Delete Older file Oracle Database automaticly using Linux Script and Crontab
This is script that export Oracle Database, archive it automatically and delete archive automatically where archive older than 20 day
####################
# Oracle Backup #
# Bayu Kurniawan R #
# 17 April 2008 #
####################
# Buat environment
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
ORACLE_HOME=/opt/oracle/product/9ir2/
ORACLE_BASE=/opt/oracle
ORACLE_SID=orcl
export ORACLE_HOME ORACLE_BASE ORACLE_SID
PATH=$PATH:$HOME/bin:$ORACLE_HOME:$ORACLE_HOME/bin
# File naming : year.month.day
tanggal=$(date +%y%m%d)
# Path to save file
dir=/home/bayu
# Daily Backup DB Oracle
echo Exporting DB Oracle ….
su - oracle -c “exp user/password@orcl file=$dir/file_$tanggal.dmp log=$dir/file_$tanggal.log”
echo Archiving Oracle Backup…
tar -zcf $dir/file_$tanggal.tar.gz $dir/file_$tanggal.dmp $dir/file_$tanggal.log
echo Removing Oracle .dmp and .log…
rm $dir/file_$tanggal.dmp $dir/file_$tanggal.log
echo Removing Dump Oracle which older than 20 day…
find /home/bayu -name file*tar.gz -mtime +20 -exec rm -f {} \
# End #
Save it as backup.sh
Edit the Crontab
crontab -e
Add following line
0 22 * * * /opt/oracle/product/9ir2/bin/backup.sh
This script will execute backup.sh everyday at 22.00









