Created
November 21, 2011 14:12
-
-
Save metalrufflez/1382720 to your computer and use it in GitHub Desktop.
Script to fully backup Oracle 10g databases (remember to alter the target date)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export ORACLE_HOME="/path/to/oracle/home" | |
export ORACLE_SID=SID | |
DB_BKPDIR="/path/to/backup/directory" | |
DMPNAME="bkp_$(date +%y%m%d).dmp" | |
TARNAME="bkp_$(date +%y%m%d).tar.bz2" | |
LOGNAME="bkp_$(date +%y%m%d).log" | |
#EXPORT DA BASE DE DADOS | |
echo "Dumping Database" | |
${ORACLE_HOME}/bin/exp \"/ as sysdba\" file=$DB_BKPDIR/$DMPNAME log=$DB_BKPDIR/$LOGNAME buffer=3000000 compress=y full=y | |
#COPIA DOS DIRETORIOS | |
echo "Packaging the datafiles" | |
#${ORACLE_HOME}/bin/dbshut | |
tar -jcvf $DB_BKPDIR/$TARNAME /u01/app/oracle/oradata/ | |
#${ORACLE_HOME}/bin/dbstart | |
echo "Bzipping the dump" | |
bzip2 $DB_BKPDIR/$DMPNAME | |
# Set 15 days to rotate the dump and logs | |
DATE_TARGET=$(perl -e 'use POSIX qw(strftime); print strftime "%y%m%d",localtime(time()-3600*24*15)') | |
# Rotating log and dump | |
echo "Cleaning old Dump/logs" | |
for FILE_NAME in $DB_BKPDIR/*{dmp.bz2,log} | |
do | |
echo $FILE_NAME | grep -q hourly && continue | |
FILE_DATE=$(echo $FILE_NAME | cut -d"_" -f2 | cut -d"." -f1) | |
if [ "$FILE_DATE" -le "$DATE_TARGET" ]; then | |
rm -f $FILE_NAME | |
fi | |
done | |
# Set 5 days to rotate the datafiles | |
DBF_DATE_TARGET=$(perl -e 'use POSIX qw(strftime); print strftime "%y%m%d",localtime(time()-3600*24*5)') | |
# Rotating datafiles | |
echo "Cleaning old datafiles" | |
for DBF_FILE_NAME in $DB_BKPDIR/*tar.bz2 | |
do | |
DBF_FILE_DATE=$(echo $DBF_FILE_NAME | cut -d"_" -f2 | cut -d"." -f1) | |
if [ "$DBF_FILE_DATE" -le "$DBF_DATE_TARGET" ]; then | |
rm -f $DBF_FILE_NAME | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment