Why are scripts needlessly complex?

Tonight i’m restoring an environment to another server as a test.   The source server is support by another group, so they use their own scripts to backup the database.  Before I started the restore I took a look at the scripts to see how its being backed up, file locations,etc and what I found utterly shocked me.

To backup one database there were at least 6 scripts scheduled in cron with a line count of almost 600 lines!   I couldn’t believe it.    I try to keep things as simple as possible.  For example, here is one of my backup scripts:

   1:  #!/bin/sh
   2:  . /home/oracle/.bash_profile
   3:  . /usr/local/bin/oraenv << END
   4:  ORCL
   5:  END
   7:  cd /home/oracle/scripts
   8:  logfile=/home/oracle/scripts/log/rman_ORCL_LVL0.log.`date '+%d%m%y'`
  10:  rman target / nocatalog CMDFILE /home/oracle/scripts/rman_ORCL_LVL0.sql LOG $logfile
  11:  status=$?
  13:  if [ $status -gt 0 ] ; then
  14:     mailx -s "[BACKUP][FAILED] ORCL LVL0" <<!
  15:  `cat $logfile`
  16:  !
  17:  else
  18:      mailx -s "[BACKUP][SUCCESS] ORCL LVL0" <<!
  19:  `cat $logfile`
  20:  !
  21:  fi
  23:  echo "Backup files removed (4+ days OLD):"
  24:  echo `find /u03/backup/ORCL  -mtime +4 -print`
  25:  find /u03/backup/ORCL -type f -mtime +4 -exec rm -f {} \;
  27:  echo "Archive logs removed (2+ days OLD):"
  28:  echo `find /u03/archive/ORCL  -mtime +2 -print`
  29:  find /u03/archive/ORCL -type f -mtime +2 -exec rm -f {} \;

It doesn’t get much simpler than that.  I send emails both on SUCCESS and FAIL of the backup because i've seen cron stop working before.   I have filters in my mail client to separate them into different folders.  Each day I checked for failed backups and periodically I check successful folder to make sure my backups are working properly.   The rman_ORCL_LVL0.sql file basically contains:  unneedlessly

   incremental level 0
   tag 'ORCL_LVL0';

I know there are exceptions but in this case these databases are small and have simple backup requirements.  Yeah, I could spend a bit of time to put in variables so its more generic but I don’t manage hundreds of databases so thats not a huge concern.  

As for the original 600 lines of scripts… Yeah, its very generic, handles a multitude of scenarios and probably even does your laundry but its worthless IMHO if it can’t be quickly understood.  The last thing I want to be doing at 3am in the morning is trying to figure out someones scripts because I was the lucky person on call.


Anonymous said...

The script looks really useful and easy to use.

Oracle Apps FAQ said...

Great Script for DBA's

Sridevi Koduru said...

Sridevi Koduru (Senior Oracle Apps Trainer
LinkedIn profile -
Please Contact for One to One Online Training on Oracle Apps Technical, Financials, SCM, Oracle Manufacturing, OAF, ADF, SQL, PL/SQL, D2K at | +91 - 9581017828.