Sunday, 17 February 2013

Backup Using Rman[status through mail]

bash-3.2$ crontab -l
30 00 * * 0-5 /u02/orauat/RMAN/rman.sh
00 00  * * * /home/orauat/scripts/RMAN_COMP/daily_rman_arch_del.sh > /home/orauat/scripts/RMAN_COMP/log/arch_del.log 2>&1
bash-3.2$

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

bash-3.2$ pwd
/u02/orauat/RMAN
bash-3.2$ cat rman.sh
#/* REM --------------------------------------------------------------------------
#
# File Name   :rman.sh
# Purpose     :To take the HOT backup using RMAN
# # --------------------------------------------------------------------------
# 




# --------------------------------------------------------------------
. /u03/orauat/db/tech_st/11.1.0/PRODTEST1_KKKMAAIND.env

export v_inst1=PRODTEST1
export v_inst2=PRODTEST2


rm -rf /u02/orauat/PRODTEST_hotbackup/PRODTEST*

rm -rf /u02/orauat/PRODTEST_hotbackup/arch*


# Step 1: Rman Backup Location variable
# --------------------------------------
BACKUP_STATUS=""
date=`date|awk '{print $2 $3}'`
DBA="dbsupport@name.com"
LOG=/u02/orauat/scripts/RMAN_COMP/log

### CROSSCHECK #######

rman target / log=$LOG/Validate_$date.log <<EOF
run {
crosscheck archivelog all;
}
exit
EOF

# Step 2: Archive log current on 1st Instance
# -------------------------------------------
sqlplus rman/password@$v_inst1 << EOF
select instance_name from v\$instance
/
alter system archive log current
/
exit
EOF

# Step 3: Archive log current on 2nd Instances
# ---------------------------------------------
sqlplus rman/password@$v_inst2 << EOF
select instance_name from v\$instance
/
alter system archive log current
/
exit
EOF

# Step 4: Rman compressed backup incremental Level 0 Backup of database
# -----------------------------------------------------------------------

rman target / log=$LOG/PRODTEST_bkp_$date.log <<EOF
RUN {
allocate channel c1 type DISK;
allocate channel c2 type DISK;
allocate channel c3 type DISK;
allocate channel c4 type DISK;
allocate channel c5 type DISK;
backup as compressed backupset incremental level 0 cumulative tag LEVEL0_BACKUP filesperset 5 format '/u02/orauat/PRODTEST_hotbackup/%d_LVL0_%T_%s' database;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
}
exit
EOF

#######

cat $LOG/PROD_bkp_$date.log >> $LOG/cron_rman.log

##################


# Step 5: Archive log current on 1st and 2nd Instances
# -------------------------------------------------------

sqlplus rman/password@$v_inst1 << EOF
select instance_name from v\$instance
/
alter system archive log current
/
exit
EOF

sqlplus rman/password@$v_inst2 << EOF
select instance_name from v\$instance
/
alter system archive log current
/
exit
EOF

# Archive log backup with controlfile
# -----------------------------------
rman target / log=$LOG/PRODTEST_archive_$date.log <<EOF
RUN {
allocate channel c1 type DISK;
allocate channel c2 type DISK;
allocate channel c3 type DISK;
allocate channel c4 type DISK;
allocate channel c5 type DISK;
backup as compressed backupset format '/u02/orauat/PRODTEST_hotbackup/arch_%e_%d_%D_%M_%Y_%s_%U.rman' archivelog all not backed up 1 times;
copy current controlfile to '/u02/orauat/PRODTEST_hotbackup/%d_control_file_%D_%T_%s';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
}
exit
EOF

#######

cat $LOG/PRODTEST_archive_$date.log >> $LOG/cron_rman.log

################

# Step 6: crosscheck and delete old backups
# ------------------------------------------------

RUN {
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete device type disk;
#delete noprompt archivelog all backed up 2 times to device type disk;
#delete archivelog until time 'SYSDATE-1';
#delete noprompt backup of archivelog all completed before 'sysdate-2';
}
exit
EOF
fi

################

rman target / log=$LOG/PRODTEST_backupset_info.log <<EOF
list backup summary;
list backupset;
list backup of controlfile;
exit
EOF


# Step 8: Mail to DBA
#---------------------

mail -s "PRODTEST RMAN Backup Completed" $DBA < $LOG/cron_rman.log

##################################

#export ext=`date +%y%m%d`
mv /u02/orauat/RMAN/RMAN_COMP/log/cron_rman.log /u02/orauat/RMAN/RMAN_COMP/log/cron_rman_$ext.log

####### DELETE 45 Days older logs #####################
find /u02/orauat/RMAN/RMAN_COMP/log -name '*.log' -mtime +45 -exec rm -f {} \;

bash-3.2$


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

bash-3.2$ pwd
/home/orauat/scripts/RMAN_COMP
bash-3.2$ cat daily_rman_arch_del.sh
#!/bin/bash
export ORACLE_HOME=/u03/orauat/db/tech_st/11.1.0
export ORACLE_SID=PRODTEST1
export PATH=$PATH:$ORACLE_HOME/bin

rman target / <<EOF
delete noprompt archivelog all completed before 'sysdate - 2';
exit;
EOF
bash-3.2$

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

No comments:

Post a Comment