scripts



Oracle Database Backup Script:
#########################################################################



#Folders to create:
#1. $BACKUP_BASE=/flasharea/rman_backup/remitdb (Just an example)
#2. $BACKUP_BASE/ARCH_BACKUP
#3. $BACKUP_BASE/LOGS
#4. $BACKUP_BASE/$FOLDER_NAME/RMAN_LOGS
#5. $BACKUP_BASE/$FOLDER_NAME/DB_BACKUPSET
#6. $BACKUP_BASE/$FOLDER_NAME/SP_BACKUP
#7. $BACKUP_BASE/$FOLDER_NAME/CF_BACKUPSET
#8. $BACKUP_BASE/$FOLDER_NAME/CF_AUTOBACKUP
#9. $BACKUP_BASE/$FOLDER_NAME/COPY_DB

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

export ORACLE_SID=remitdb

export PATH=$PATH:$ORACLE_HOME/bin

export BACKUP_BASE=/flasharea/rman_backup/remitdb

export DATE_WITH_TIME=`date +%Y%m%d-%H%M%S`

export DATE_TIME=`date +%Y%m%d`

#export DATE_TIME=`date +%Y%m%d-%H%M%S`

export FOLDER_NAME="DB"_$DATE_TIME

############################# CREATING NECESSARY FOLDERS FOR BACKUP ####################################

#echo Starting Backup ...................................................................................
#echo `date +%m%d%Y-%H%M%S` >> $BACKUP_BASE/RMAN_LOGS/DB_""$DATE_TIME.log

echo Creating backup destination folders ................................................................

echo Creating backup destination folders $BACKUP_BASE/RMAN_LOGS for RMAN Log files history...............
mkdir -p $BACKUP_BASE/RMAN_LOGS

#echo Creating backup destination folders $BACKUP_BASE/LOGS for RMAN log files.................
#mkdir -p $BACKUP_BASE/LOGS


echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/LOGS for RMAN log files.................
mkdir -p $BACKUP_BASE/$FOLDER_NAME/LOGS

echo Creating Log file $BACKUP_BASE/$FOLDER_NAME/LOGS/DB_""$DATE_WITH_TIME.log for current operation
export LOG_FILE_NAME=$BACKUP_BASE/$FOLDER_NAME/LOGS/DB_""$DATE_WITH_TIME.log

touch $LOG_FILE_NAME

echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/ARCH_BACKUP for archive log files..................
mkdir -p $BACKUP_BASE/$FOLDER_NAME/ARCH_BACKUP

echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/DB_BACKUPSET for DB Backupsets..........
mkdir -p $BACKUP_BASE/$FOLDER_NAME/DB_BACKUPSET

echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/SP_BACKUP for spfile....................
mkdir -p $BACKUP_BASE/$FOLDER_NAME/SP_BACKUP

echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/CF_BACKUP for controlfile...............
mkdir -p $BACKUP_BASE/$FOLDER_NAME/CF_BACKUP

#echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/COPY_DB for RMAN copy of database.......
#mkdir -p $BACKUP_BASE/$FOLDER_NAME/COPY_DB

############################# FINISHED CREATING NECESSARY FOLDERS FOR BACKUP ##############################

$ORACLE_HOME/bin/rman target / nocatalog log = $LOG_FILE_NAME append << EOF

run
{
        ALLOCATE CHANNEL c1 DEVICE TYPE DISK MAXPIECESIZE 2G;

        #ALLOCATE CHANNEL c2 DEVICE TYPE DISK MAXPIECESIZE 2G;

        #ALLOCATE CHANNEL c3 DEVICE TYPE DISK MAXPIECESIZE 2G;

        CONFIGURE CONTROLFILE AUTOBACKUP ON;
        CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '$BACKUP_BASE/$FOLDER_NAME/CF_BACKUP/CF_AUTO_%F';

        #Retention policy to be defined by client
        CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;

        SQL "ALTER SYSTEM SWITCH LOGFILE";

        #####BACKUP AS BACKUPSET DATABASE FORMAT '$BACKUP_BASE/$FOLDER_NAME/DB_BACKUPSET/DB_%U';

        BACKUP DATABASE FORMAT '$BACKUP_BASE/$FOLDER_NAME/DB_BACKUPSET/DB_%U';

        #####BACKUP AS COMPRESSED BACKUPSET DATABASE FORMAT '$BACKUP_BASE/$FOLDER_NAME/DB_BACKUPSET/DB_%U';

        BACKUP ARCHIVELOG ALL FORMAT '$BACKUP_BASE/$FOLDER_NAME/ARCH_BACKUP/ARCH_%U' NOT BACKED UP 2 TIMES SKIP INACCESSIBLE;

        #####BACKUP AS COMPRESSED BACKUPSET ARCHIVELOG ALL FORMAT '$BACKUP_BASE/$FOLDER_NAME/ARCH_BACKUP/ARCH_%U' NOT BACKED UP 2 TIMES SKIP INACCESSIBLE;

        #Enable the DELETE command below on confirmation with client.
        DELETE NOPROMPT ARCHIVELOG ALL BACKED UP 2 TIMES TO DISK;

        BACKUP SPFILE FORMAT '$BACKUP_BASE/$FOLDER_NAME/SP_BACKUP/SP_%U';

        BACKUP CURRENT CONTROLFILE FORMAT '$BACKUP_BASE/$FOLDER_NAME/CF_BACKUP/CF_BS_%d_%u_%s_%T';

        COPY CURRENT CONTROLFILE to '$BACKUP_BASE/$FOLDER_NAME/CF_BACKUP/control01.ctl';
        #CROSSCHECK BACKUP;

        release channel c1;
        #release channel c2;
        #release channel c3;
}

exit;


EOF

cp $LOG_FILE_NAME $BACKUP_BASE/RMAN_LOGS
cp $ORACLE_HOME/dbs/initremitdb.ora $BACKUP_BASE/$FOLDER_NAME/SP_BACKUP/initremitdb.ora

echo Backup RMAN log files: cp $LOG_FILE_NAME $BACKUP_BASE/RMAN_LOGS  >> $LOG_FILE_NAME

echo 'End RMAN Backup of pigeon Database:'  >> $LOG_FILE_NAME

date  >> $LOG_FILE_NAME

exit


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


Rman Archive File backup script
###########################################################################


#Folders to create:
#1. $BACKUP_BASE=/flasharea/rman_backup/remitdb (Just an example)
#2. $BACKUP_BASE/ARCH_BACKUP
#3. $BACKUP_BASE/LOGS
#4. $BACKUP_BASE/$FOLDER_NAME/RMAN_LOGS
#5. $BACKUP_BASE/$FOLDER_NAME/DB_BACKUPSET
#6. $BACKUP_BASE/$FOLDER_NAME/SP_BACKUP
#7. $BACKUP_BASE/$FOLDER_NAME/CF_BACKUPSET
#8. $BACKUP_BASE/$FOLDER_NAME/CF_AUTOBACKUP
#9. $BACKUP_BASE/$FOLDER_NAME/COPY_DB

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

export ORACLE_SID=remitdb

export PATH=$PATH:$ORACLE_HOME/bin

export BACKUP_BASE=/flasharea/rman_backup/remitdb

export DATE_WITH_TIME=`date +%Y%m%d-%H%M%S`

export DATE_TIME=`date +%Y%m%d`

#export DATE_TIME=`date +%Y%m%d-%H%M%S`

export FOLDER_NAME="ARCH"_$DATE_TIME

############################# CREATING NECESSARY FOLDERS FOR BACKUP ####################################

#echo Starting Backup ...................................................................................
#echo `date +%m%d%Y-%H%M%S` >> $BACKUP_BASE/RMAN_LOGS/ARCH_""$DATE_TIME.log

echo Creating backup destination folders ................................................................

echo Creating backup destination folders $BACKUP_BASE/RMAN_LOGS for RMAN Log files history...............
mkdir -p $BACKUP_BASE/RMAN_LOGS

#echo Creating backup destination folders $BACKUP_BASE/LOGS for RMAN log files.................
#mkdir -p $BACKUP_BASE/LOGS


echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/LOGS for RMAN log files.................
mkdir -p $BACKUP_BASE/$FOLDER_NAME/LOGS

echo Creating Log file $BACKUP_BASE/$FOLDER_NAME/LOGS/ARCH_""$DATE_WITH_TIME.log for current operation
export LOG_FILE_NAME=$BACKUP_BASE/$FOLDER_NAME/LOGS/ARCH_""$DATE_WITH_TIME.log

touch $LOG_FILE_NAME

echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/ARCH_BACKUP for archive log files..................
mkdir -p $BACKUP_BASE/$FOLDER_NAME/ARCH_BACKUP

#echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/DB_BACKUPSET for DB Backupsets..........
#mkdir -p $BACKUP_BASE/$FOLDER_NAME/DB_BACKUPSET

echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/SP_BACKUP for spfile....................
mkdir -p $BACKUP_BASE/$FOLDER_NAME/SP_BACKUP

echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/CF_BACKUP for controlfile...............
mkdir -p $BACKUP_BASE/$FOLDER_NAME/CF_BACKUP

#echo Creating backup destination folders $BACKUP_BASE/$FOLDER_NAME/COPY_DB for RMAN copy of database.......
#mkdir -p $BACKUP_BASE/$FOLDER_NAME/COPY_DB

############################# FINISHED CREATING NECESSARY FOLDERS FOR BACKUP ##############################

$ORACLE_HOME/bin/rman target / nocatalog log = $LOG_FILE_NAME << EOF

run
{
        ALLOCATE CHANNEL c1 DEVICE TYPE DISK MAXPIECESIZE 2G;

        #ALLOCATE CHANNEL c2 DEVICE TYPE DISK MAXPIECESIZE 2G;

        #ALLOCATE CHANNEL c3 DEVICE TYPE DISK MAXPIECESIZE 2G;

        CONFIGURE CONTROLFILE AUTOBACKUP ON;
        CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '$BACKUP_BASE/$FOLDER_NAME/CF_BACKUP/CF_AUTO_%F';

        #Retention policy to be defined by client
        CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;

        SQL "ALTER SYSTEM SWITCH LOGFILE";

        ###BACKUP AS BACKUPSET DATABASE FORMAT '$BACKUP_BASE/$FOLDER_NAME/DB_BACKUPSET/DB_%U';

        #####BACKUP AS COMPRESSED BACKUPSET ARCHIVELOG ALL FORMAT '$BACKUP_BASE/$FOLDER_NAME/ARCH_BACKUP/ARCH_%U' NOT BACKED UP 2 TIMES SKIP INACCESSIBLE;

        #####BACKUP ARCHIVELOG ALL FORMAT '$BACKUP_BASE/$FOLDER_NAME/ARCH_BACKUP/ARCH_%U' NOT BACKED UP 2 TIMES SKIP INACCESSIBLE;

        BACKUP ARCHIVELOG ALL FORMAT '$BACKUP_BASE/$FOLDER_NAME/ARCH_BACKUP/ARCH_%U' NOT BACKED UP 2 TIMES;

        #Enable the DELETE command below on confirmation with client.
        DELETE NOPROMPT ARCHIVELOG ALL BACKED UP 2 TIMES TO DISK;

        BACKUP SPFILE FORMAT '$BACKUP_BASE/$FOLDER_NAME/SP_BACKUP/SP_%U';

        BACKUP CURRENT CONTROLFILE FORMAT '$BACKUP_BASE/$FOLDER_NAME/CF_BACKUP/CF_BS_%d_%u_%s_%T';

        COPY CURRENT CONTROLFILE to '$BACKUP_BASE/$FOLDER_NAME/CF_BACKUP/control01.ctl';
        #CROSSCHECK BACKUP;

        release channel c1;
        #release channel c2;
        #release channel c3;
}

exit;


EOF

cp $LOG_FILE_NAME $BACKUP_BASE/RMAN_LOGS
cp $ORACLE_HOME/dbs/initremitdb.ora $BACKUP_BASE/$FOLDER_NAME/SP_BACKUP/initremitdb.ora

echo Backup RMAN log files: cp $LOG_FILE_NAME $BACKUP_BASE/RMAN_LOGS  >> $LOG_FILE_NAME

echo 'End RMAN Backup of pigeon Database archives:'  >> $LOG_FILE_NAME

date  >> $LOG_FILE_NAME


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

No comments:

Post a Comment