RMAN backup script best practise

$ cat rmanbackup.sh
# export variables
ORACLE_BASE=/u01/app/oracle
export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_HOME
ORACLE_SID=LIVEDB1
export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH
export PATH


#or


export PATH=/usr/bin:/usr/local/bin:/usr/ccs/bin
export NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS'
export ORACLE_SID=PROD


ORAENV_ASK=NO
. oraenv
unset ORAENV_ASK


# other variables
week=`date +%w`
LOGFILE=/u01/app/oracle/admin/LIVEDB/backup/backup.log
export TIMESTAMP=`date +%Y-%m-%d-%T`
export WEEK=`date +%w`
export TRACE=/u01/app/backup/controlfile.backup.${week}.sql
export PFILE=/u01/app/backup/spfile.backup
export EMAIL="jephe@domain.com"



# create lock file

PRG=`basename $0`
LOCKFILE=/tmp/$PRG.lock
if [ -f $LOCKFILE ]; then
echo "lock file exists, exiting..."
exit 1
else
echo "DO NOT REMOVE, $LOCKFILE" > $LOCKFILE
 fi 



rman target / <<ERMAN > $LOGFILE

set echo on;
# controlfile autobackup
CONFIGURE CONTROLFILE AUTOBACKUP ON;
or
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/dir/cf%F';


# The %F element of the format string combines the DBID, day, month, year, and sequence number to # generate a unique filename. %F must be included in any control file autobackup format.


#retention policy
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
or
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;




show all;
report unrecoverable;


# actual backup
backup database plus archivelog;

#Note: this step will do the following:
# alter system archive log current;
# backup archivelog all;
# backup database
# backup controlfile and spfile if autobackup is on
# alter system archive log current ;
# backup archivelog that generated during rman backup, which means backup the archivelog that generated by above command.




# delete obsolete;
# report obsolete;
delete force noprompt obsolete;


# controlfile/pfile backup
sql 'ALTER DATABASE BACKUP CONTROLFILE TO TRACE';
sql "ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS ''/u01/app/backup/controlfile.backup.${week}.sql'' reuse";
sql "CREATE PFILE=''/u01/app/backup/spfile.backup'' FROM SPFILE";


# crosscheck
crosscheck archivelog all;
delete noprompt expired archivelog all;
crosscheck backup;
delete noprompt expired backup;
crosscheck copy;
delete noprompt expired copy;


# list
# list backup by file;
# list backup of database by backup;
# list expired backup;
# list expired copy;
list backup;
list backup summary;
list backup recoverable;


# report
# report need backup database;
# report obsolete;
# report schema;
report unrecoverable;


#  test restore
restore database validate;
restore spfile validate;
restore controlfile validate;
restore archivelog from time 'sysdate-1' validate;
# restore controlfile to '/path/to/' validate;
# restore archivelog all validate;
# restore archivelog from time 'sysdate-1' validate check logical;
# restore database validate check logical;


# restore tablespace users validate;


Note: The RESTORE DATABASE VALIDATE command will check for the last level 0 or FULL tape or disk based backup, but the RESTORE ARCHIVELOG ALL command will check for all the archivelog files catalogued based on the retention policy


exit
ERMAN


mailx -s "controlfile trace backup for PROD"  $EMAIL <  $TRACE
mailx -s "pfile backup for PROD"  $EMAIL <  $PFILE