Wednesday, September 28, 2016

Basic Shell Script for Oracle RMAN backup


#Oracle RMAN backup by Surapong Naowasate
#!/bin/bash
cd
. .bash_profile
export BACKUPPATH="/Path_to_Store_RMAN_BACKUPSET"

for i in DB1 DB2....DBn
do
export DATAFILE="BACKUP_${i}_DATA_$(date '+%Y%m%d')"
echo $DATAFILE
export ARCHIVEDLOG="BACKUP_${i}_ARC_$(date '+%Y%m%d')"
echo $ARCHIVEDLOG
export CONTROLFILE="BACKUP_${i}_CTL_$(date '+%Y%m%d')"
echo $CONTROLFILE
export RMAN_LOG_FILE="BACKUP_${i}_$(date '+%Y%m%d').out"
echo $RMAN_LOG_FILE
echo Backup_data_file_path=$BACKUPPATH

export ORACLE_SID=$i

#EXPORT pfile
sqlplus '/ as sysdba' << EOF
CREATE pfile='${BACKUPPATH}/${i}/pfile-$i-$(date '+%Y%m%d').ora' from spfile;
EXIT;
EOF

#RMAN REPORT DATABASE INFORMATION
rman target / msglog ${BACKUPPATH}/${i}/DATABASE_${i}_info.txt <<EOF
run
{
REPORT SCHEMA;
}
EXIT;
EOF
#<<'test'
#RMAN BACKUPSET FOR Migration
rman target / msglog ${BACKUPPATH}/log/$RMAN_LOG_FILE <<EOF
run
{
ALLOCATE CHANNEL ch00 TYPE DISK;
ALLOCATE CHANNEL ch01 TYPE DISK;
ALLOCATE CHANNEL ch02 TYPE DISK;
ALLOCATE CHANNEL ch03 TYPE DISK;

BACKUP
TAG "${DATAFILE}"
FORMAT '${BACKUPPATH}/${i}/DATA_${i}_%s_%p_%t'
DATABASE;
sql 'alter system archive log current';
RELEASE CHANNEL ch00;
RELEASE CHANNEL ch01;
RELEASE CHANNEL ch02;
RELEASE CHANNEL ch03;

ALLOCATE CHANNEL ch00 TYPE DISK;
ALLOCATE CHANNEL ch01 TYPE DISK;

BACKUP
TAG "${ARCHIVEDLOG}"
FORMAT '${BACKUPPATH}/${i}/arc_${i}_%s_%p_%t'
ARCHIVELOG ALL ;
RELEASE CHANNEL ch00;
RELEASE CHANNEL ch01;

ALLOCATE CHANNEL ch00 TYPE DISK;
BACKUP
TAG "${CONTROLFILE}"
FORMAT '${BACKUPPATH}/${i}/cntrl_${i}_%s_%p_%t'
CURRENT CONTROLFILE;
RELEASE CHANNEL ch00;
}
EXIT;
EOF
#test
echo $i
done

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

ALCATEL 6900

write memory copy running certified reload from working no rollback-timeout