Backup Script - Veritas Net Backup

This is a discussion on Backup Script - Veritas Net Backup ; Can the following script be modified to to to netbackup. If so can someone point me in the right direction. #!/usr/bin/sh # Run .profile for standard environment . ${HOME}/.profile TERM=vt100; export TERM ORAENV_ASK=NO; export ORAENV_ASK ORACLE_SID=gglp; export ORACLE_SID # This ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Backup Script

  1. Backup Script


    Can the following script be modified to to to netbackup. If so
    can someone point me in the right direction.

    #!/usr/bin/sh

    # Run .profile for standard environment
    . ${HOME}/.profile
    TERM=vt100; export TERM
    ORAENV_ASK=NO; export ORAENV_ASK
    ORACLE_SID=gglp; export ORACLE_SID

    # This script runs the online backups for the Oracle database.
    # It takes each database tablespace offline in turn, tars the
    # database files to an archive, and then returns the tablespace
    # to an online status.

    # Establish the local processing variables.

    PROGNAME=`basename ${0}`
    DB_CONNECT_STRING=${1}
    NBR_OF_ARGS_PROVIDED=${#}
    NBR_OF_ARGS_EXPECTED=1
    SQL_CMD=`whence sqlplus`
    BACKUPDIR=/kb01/oradata/gglp/backup
    BACKUPFILE=${BACKUPDIR}/control_init_backup_`date +%m%d%y`.tar
    BACKUPFILE1=${BACKUPDIR}/redo_log_backup_`date +%m%d%y`.tar
    BACKUPFILE2=${BACKUPDIR}/archive_log_backup_`date +%m%d%y`.tar
    EXECFILE=/tmp/execfile.ksh
    LOGDIR=${BACKUPDIR}/logs
    LOGFILE=${LOGDIR}/online_backup_`date +%a`.log
    SUCCESS=0
    FAILURE=1

    # Check for the proper number of input parameters


    if [ ${NBR_OF_ARGS_PROVIDED} -ne ${NBR_OF_ARGS_EXPECTED} ]

    then

    echo "\nError- improper number of arguments\nUsage: \n\t${PROGNAME} "
    exit ${FAILURE}

    fi


    ################################################## ##################
    #
    # Back up the database data files.
    #
    ################################################## ##################

    # Build the list of tablespaces and the associated filenames of each.

    ${SQL_CMD} -s ${DB_CONNECT_STRING} << TOAST

    set echo off;
    set feedback off;
    set heading off;
    set verify off;
    set termout off;
    set scan off;
    set pagesize 0;

    spool /tmp/DATAFILES;

    REM Obtain the files of the tablespaces;

    select tablespace_name || ':' ||
    file_name
    from dba_data_files
    order by
    tablespace_name,
    file_name;

    spool off;

    REM Build the list of database control files.

    spool /tmp/CONTROLFILES;

    select name
    from v\$controlfile
    order by
    name;

    spool off;

    REM Build the list of database logfiles." >> ${EXECFILE}

    spool /tmp/LOGFILES;

    select member
    from v\$logfile
    order by
    member;

    spool off;

    exit;
    TOAST

    # Build the executable script file to perform the online backup.

    echo "#!/bin/ksh" > ${EXECFILE}
    echo ". ~oracle/.profile" >> ${EXECFILE}
    echo "# Create the tar file to hold the backups." >> ${EXECFILE}
    echo " " >> ${EXECFILE}
    echo "touch tarseed" >> ${EXECFILE}
    echo "tar -cvf ${BACKUPFILE} tarseed" >> ${EXECFILE}
    echo "${SQL_CMD} ${DB_CONNECT_STRING} << TOAST" >> ${EXECFILE}
    echo "set serveroutput off;" >> ${EXECFILE}
    echo "set scan off;" >> ${EXECFILE}

    TAR_SWITCH='0'
    PREV_TABLESPACE='FIRST'
    for file in `cat /tmp/DATAFILES.lst`
    do
    TABLESPACE=`echo ${file} | cut -f1 -d":"`
    DATAFILE=`echo ${file} | cut -f2 -d":"`
    TSBACKUPFILE=${BACKUPDIR}/`basename ${DATAFILE} | cut -f1 -d"."`_backup_`date
    +%m%d%y`.tar
    if [ ${PREV_TABLESPACE} != ${TABLESPACE} ]
    then
    if [ ${PREV_TABLESPACE} != 'FIRST' ]
    then
    echo "alter tablespace ${PREV_TABLESPACE} end backup;" >> ${EXECFILE}
    echo "prompt Completed backup of tablespace ${PREV_TABLESPACE} on
    " >> ${EXECFILE}
    echo "host date;" >> ${EXECFILE}
    fi
    echo " " >> ${EXECFILE}
    echo "REM Backup of tablespace ${TABLESPACE}" >> ${EXECFILE}
    echo "REM Datafile ${DATAFILE}" >> ${EXECFILE}
    echo " " >> ${EXECFILE}
    echo "prompt Beginning backup of tablespace ${TABLESPACE} on " >> ${EXECFILE}
    echo "host date;" >> ${EXECFILE}
    echo "alter tablespace ${TABLESPACE} begin backup;" >> ${EXECFILE}
    PREV_TABLESPACE=${TABLESPACE}
    fi
    if [ ${TAR_SWITCH} = '0' ]
    then
    echo "host tar -cvf ${TSBACKUPFILE} ${DATAFILE} &" >> ${EXECFILE}
    PREV_TSBACKUPFILE=${TSBACKUPFILE}
    TAR_SWITCH='1'
    else
    echo "host tar -cvf ${TSBACKUPFILE} ${DATAFILE} " >> ${EXECFILE}
    TAR_SWITCH='0'
    fi
    done
    echo "alter tablespace ${PREV_TABLESPACE} end backup;" >> ${EXECFILE}
    echo "prompt Completed backup of tablespace ${PREV_TABLESPACE} on " >> ${EXECFILE}
    echo "host date;" >> ${EXECFILE}

    ################################################## ##################
    #
    # Back up the database control files.
    #
    ################################################## ##################

    # Back up the database control files.

    echo " " >> ${EXECFILE}
    echo "REM Backing up the control file" >> ${EXECFILE}
    echo " " >> ${EXECFILE}
    if [ -f ${BACKUPDIR}/controlfile.ctl ]
    then
    REUSE=reuse
    else
    REUSE=
    fi
    echo "alter database backup controlfile to '${BACKUPDIR}/controlfile.ctl'
    ${REUSE};" >> ${EXECFILE}

    echo "host tar -rvf ${BACKUPFILE} ${BACKUPDIR}/controlfile.ctl" >> ${EXECFILE}

    echo " " >> ${EXECFILE}
    echo "REM Back up the database control files." >> ${EXECFILE}
    echo " " >> ${EXECFILE}

    for file in `cat /tmp/CONTROLFILES.lst`
    do
    echo "host tar -rvf ${BACKUPFILE} ${file}" >> ${EXECFILE}
    done

    ################################################## ##################
    #
    # Back up the database init files.
    #
    ################################################## ##################

    echo " " >> ${EXECFILE}
    echo "REM Back up the database init files." >> ${EXECFILE}
    echo " " >> ${EXECFILE}
    echo "host tar -rvf ${BACKUPFILE} ${ORACLE_HOME}/dbs/initgglp.ora" >> ${EXECFILE}
    echo " " >> ${EXECFILE}

    ################################################## ##################
    #
    # Back up the database log files.
    #
    ################################################## ##################

    echo " " >> ${EXECFILE}
    echo "REM Back up the database log files." >> ${EXECFILE}
    echo " " >> ${EXECFILE}

    for file in `cat /tmp/LOGFILES.lst`
    do
    echo "host tar -rvf ${BACKUPFILE1} ${file}" >> ${EXECFILE}
    done

    # Perform a redo log switch to archive redo logs used during the backup.

    echo " " >> ${EXECFILE}
    echo "REM Switching the redo log to back up the redo log used" >> ${EXECFILE}
    echo "REM during tablespace backup." >> ${EXECFILE}
    echo " " >> ${EXECFILE}
    echo "alter system switch logfile;" >> ${EXECFILE}

    echo "exit;" >> ${EXECFILE}
    echo "TOAST" >> ${EXECFILE}

    ################################################## ##################
    #
    # Back up the archived redo log files.
    #
    ################################################## ##################
    # Get the archive log directory.

    svrmgrl << TOAST > /tmp/ARCHFILES
    connect internal;
    show parameter log_archive_dest;
    exit;
    TOAST

    # Suspend the redo log archiving process.

    echo " " >> ${EXECFILE}
    echo "# Suspend the redo log archiving process." >> ${EXECFILE}
    echo " " >> ${EXECFILE}
    echo "svrmgrl << TOAST" >> ${EXECFILE}
    echo "connect internal;" >> ${EXECFILE}
    echo "archive log stop;" >> ${EXECFILE}
    echo "exit;" >> ${EXECFILE}
    echo "TOAST" >> ${EXECFILE}

    echo " " >> ${EXECFILE}
    echo "# Tar the archived redo log files." >> ${EXECFILE}
    echo " " >> ${EXECFILE}
    ARCH_DIR=`grep log_archive_dest \/tmp\/ARCHFILES | awk '{print \$3}'`
    for ARCH_FILE in `ls \${ARCH_DIR}`
    do
    echo "tar -rvf ${BACKUPFILE2} ${ARCH_DIR}/${ARCH_FILE}" >> ${EXECFILE}
    done
    echo " " >> ${EXECFILE}

    #echo "rm /tmp/ARCHFILES" >> ${EXECFILE}

    # Restart the redo log archiving process.

    echo "# Restart the redo log archiving process." >> ${EXECFILE}
    echo " " >> ${EXECFILE}
    echo "svrmgrl << TOAST" >> ${EXECFILE}
    echo "connect internal;" >> ${EXECFILE}
    echo "archive log start;" >> ${EXECFILE}
    echo "exit;" >> ${EXECFILE}
    echo "TOAST" >> ${EXECFILE}
    echo " " >> ${EXECFILE}

    # Verify that the tar commands issued above were successful.
    # Since tar was issued from within SQL*PLUS, we need to scan the logfile
    # for error messages.

    echo "# Verify that the tar commands issued above were successful." >> ${EXECFILE}
    echo "# Since tar was issued from within SQL*PLUS, we need to scan the logfile"
    >> ${EXECFILE}

    echo "# for error messages." >> ${EXECFILE}
    echo " " >> ${EXECFILE}
    echo "fgrep -s \"tar:\" ${LOGFILE}" >> ${EXECFILE}
    echo "tarstatus=\$?" >> ${EXECFILE}
    echo "if [ \$tarstatus = 0 ]" >> ${EXECFILE}
    echo "then" >> ${EXECFILE}
    echo " echo \"${PROGNAME}: tar command unsuccessful.\"" >> ${EXECFILE}
    echo " echo \"${PROGNAME} exiting at `date`.\"" >> ${EXECFILE}
    echo " exit ${FAILURE}" >> ${EXECFILE}
    echo "else" >> ${EXECFILE}
    echo " echo \"${PROGNAME}: tar commands successful.\"" >> ${EXECFILE}
    echo "fi" >> ${EXECFILE}
    echo "echo \"Finished execution of ${EXECFILE} on `date`.\n\"" >> ${EXECFILE}

    echo "exit" >> ${EXECFILE}

    # Now make the executable file executable.

    chmod 740 ${EXECFILE}

    # Execute the online backup executable file.

    echo "**** Beginning the online backup on `date` ****" > ${LOGFILE}
    . ${EXECFILE} >> ${LOGFILE} 2>&1
    echo "**** Completed the online backup on `date` ****" >> ${LOGFILE}

    echo "Finished executing script ${PROGNAME} on `date`.\n"
    exit


  2. Re: Backup Script

    After your online backups of the Oracle database is complete, call a netbackup script to
    execute a backup ( using the bpbkar command -- see the Admin Guide) -- then a class needs to be
    set up on the backup server that has a User Schedule.

    Dan Chrastil wrote:

    > Can the following script be modified to to to netbackup. If so
    > can someone point me in the right direction.
    >
    > #!/usr/bin/sh
    >
    > # Run .profile for standard environment
    > ${HOME}/.profile
    > TERM=vt100; export TERM
    > ORAENV_ASK=NO; export ORAENV_ASK
    > ORACLE_SID=gglp; export ORACLE_SID
    >
    > # This script runs the online backups for the Oracle database.
    > # It takes each database tablespace offline in turn, tars the
    > # database files to an archive, and then returns the tablespace
    > # to an online status.
    >
    > # Establish the local processing variables.
    >
    > PROGNAME=`basename ${0}`
    > DB_CONNECT_STRING=${1}
    > NBR_OF_ARGS_PROVIDED=${#}
    > NBR_OF_ARGS_EXPECTED=1
    > SQL_CMD=`whence sqlplus`
    > BACKUPDIR=/kb01/oradata/gglp/backup
    > BACKUPFILE=${BACKUPDIR}/control_init_backup_`date +%m%d%y`.tar
    > BACKUPFILE1=${BACKUPDIR}/redo_log_backup_`date +%m%d%y`.tar
    > BACKUPFILE2=${BACKUPDIR}/archive_log_backup_`date +%m%d%y`.tar
    > EXECFILE=/tmp/execfile.ksh
    > LOGDIR=${BACKUPDIR}/logs
    > LOGFILE=${LOGDIR}/online_backup_`date +%a`.log
    > SUCCESS=0
    > FAILURE=1
    >
    > # Check for the proper number of input parameters
    >
    >
    > if [ ${NBR_OF_ARGS_PROVIDED} -ne ${NBR_OF_ARGS_EXPECTED} ]
    >
    > then
    >
    > echo "\nError- improper number of arguments\nUsage: \n\t${PROGNAME} "
    > exit ${FAILURE}
    >
    > fi
    >
    >
    > ################################################## ##################
    > #
    > # Back up the database data files.
    > #
    > ################################################## ##################
    >
    > # Build the list of tablespaces and the associated filenames of each.
    >
    > ${SQL_CMD} -s ${DB_CONNECT_STRING} << TOAST
    >
    > set echo off;
    > set feedback off;
    > set heading off;
    > set verify off;
    > set termout off;
    > set scan off;
    > set pagesize 0;
    >
    > spool /tmp/DATAFILES;
    >
    > REM Obtain the files of the tablespaces;
    >
    > select tablespace_name || ':' ||
    > file_name
    > from dba_data_files
    > order by
    > tablespace_name,
    > file_name;
    >
    > spool off;
    >
    > REM Build the list of database control files.
    >
    > spool /tmp/CONTROLFILES;
    >
    > select name
    > from v\$controlfile
    > order by
    > name;
    >
    > spool off;
    >
    > REM Build the list of database logfiles." >> ${EXECFILE}
    >
    > spool /tmp/LOGFILES;
    >
    > select member
    > from v\$logfile
    > order by
    > member;
    >
    > spool off;
    >
    > exit;
    > TOAST
    >
    > # Build the executable script file to perform the online backup.
    >
    > echo "#!/bin/ksh" > ${EXECFILE}
    > echo ". ~oracle/.profile" >> ${EXECFILE}
    > echo "# Create the tar file to hold the backups." >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    > echo "touch tarseed" >> ${EXECFILE}
    > echo "tar -cvf ${BACKUPFILE} tarseed" >> ${EXECFILE}
    > echo "${SQL_CMD} ${DB_CONNECT_STRING} << TOAST" >> ${EXECFILE}
    > echo "set serveroutput off;" >> ${EXECFILE}
    > echo "set scan off;" >> ${EXECFILE}
    >
    > TAR_SWITCH='0'
    > PREV_TABLESPACE='FIRST'
    > for file in `cat /tmp/DATAFILES.lst`
    > do
    > TABLESPACE=`echo ${file} | cut -f1 -d":"`
    > DATAFILE=`echo ${file} | cut -f2 -d":"`
    > TSBACKUPFILE=${BACKUPDIR}/`basename ${DATAFILE} | cut -f1 -d"."`_backup_`date
    > +%m%d%y`.tar
    > if [ ${PREV_TABLESPACE} != ${TABLESPACE} ]
    > then
    > if [ ${PREV_TABLESPACE} != 'FIRST' ]
    > then
    > echo "alter tablespace ${PREV_TABLESPACE} end backup;" >> ${EXECFILE}
    > echo "prompt Completed backup of tablespace ${PREV_TABLESPACE} on
    > " >> ${EXECFILE}
    > echo "host date;" >> ${EXECFILE}
    > fi
    > echo " " >> ${EXECFILE}
    > echo "REM Backup of tablespace ${TABLESPACE}" >> ${EXECFILE}
    > echo "REM Datafile ${DATAFILE}" >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    > echo "prompt Beginning backup of tablespace ${TABLESPACE} on " >> ${EXECFILE}
    > echo "host date;" >> ${EXECFILE}
    > echo "alter tablespace ${TABLESPACE} begin backup;" >> ${EXECFILE}
    > PREV_TABLESPACE=${TABLESPACE}
    > fi
    > if [ ${TAR_SWITCH} = '0' ]
    > then
    > echo "host tar -cvf ${TSBACKUPFILE} ${DATAFILE} &" >> ${EXECFILE}
    > PREV_TSBACKUPFILE=${TSBACKUPFILE}
    > TAR_SWITCH='1'
    > else
    > echo "host tar -cvf ${TSBACKUPFILE} ${DATAFILE} " >> ${EXECFILE}
    > TAR_SWITCH='0'
    > fi
    > done
    > echo "alter tablespace ${PREV_TABLESPACE} end backup;" >> ${EXECFILE}
    > echo "prompt Completed backup of tablespace ${PREV_TABLESPACE} on " >> ${EXECFILE}
    > echo "host date;" >> ${EXECFILE}
    >
    > ################################################## ##################
    > #
    > # Back up the database control files.
    > #
    > ################################################## ##################
    >
    > # Back up the database control files.
    >
    > echo " " >> ${EXECFILE}
    > echo "REM Backing up the control file" >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    > if [ -f ${BACKUPDIR}/controlfile.ctl ]
    > then
    > REUSE=reuse
    > else
    > REUSE=
    > fi
    > echo "alter database backup controlfile to '${BACKUPDIR}/controlfile.ctl'
    > ${REUSE};" >> ${EXECFILE}
    >
    > echo "host tar -rvf ${BACKUPFILE} ${BACKUPDIR}/controlfile.ctl" >> ${EXECFILE}
    >
    > echo " " >> ${EXECFILE}
    > echo "REM Back up the database control files." >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    >
    > for file in `cat /tmp/CONTROLFILES.lst`
    > do
    > echo "host tar -rvf ${BACKUPFILE} ${file}" >> ${EXECFILE}
    > done
    >
    > ################################################## ##################
    > #
    > # Back up the database init files.
    > #
    > ################################################## ##################
    >
    > echo " " >> ${EXECFILE}
    > echo "REM Back up the database init files." >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    > echo "host tar -rvf ${BACKUPFILE} ${ORACLE_HOME}/dbs/initgglp.ora" >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    >
    > ################################################## ##################
    > #
    > # Back up the database log files.
    > #
    > ################################################## ##################
    >
    > echo " " >> ${EXECFILE}
    > echo "REM Back up the database log files." >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    >
    > for file in `cat /tmp/LOGFILES.lst`
    > do
    > echo "host tar -rvf ${BACKUPFILE1} ${file}" >> ${EXECFILE}
    > done
    >
    > # Perform a redo log switch to archive redo logs used during the backup.
    >
    > echo " " >> ${EXECFILE}
    > echo "REM Switching the redo log to back up the redo log used" >> ${EXECFILE}
    > echo "REM during tablespace backup." >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    > echo "alter system switch logfile;" >> ${EXECFILE}
    >
    > echo "exit;" >> ${EXECFILE}
    > echo "TOAST" >> ${EXECFILE}
    >
    > ################################################## ##################
    > #
    > # Back up the archived redo log files.
    > #
    > ################################################## ##################
    > # Get the archive log directory.
    >
    > svrmgrl << TOAST > /tmp/ARCHFILES
    > connect internal;
    > show parameter log_archive_dest;
    > exit;
    > TOAST
    >
    > # Suspend the redo log archiving process.
    >
    > echo " " >> ${EXECFILE}
    > echo "# Suspend the redo log archiving process." >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    > echo "svrmgrl << TOAST" >> ${EXECFILE}
    > echo "connect internal;" >> ${EXECFILE}
    > echo "archive log stop;" >> ${EXECFILE}
    > echo "exit;" >> ${EXECFILE}
    > echo "TOAST" >> ${EXECFILE}
    >
    > echo " " >> ${EXECFILE}
    > echo "# Tar the archived redo log files." >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    > ARCH_DIR=`grep log_archive_dest \/tmp\/ARCHFILES | awk '{print \$3}'`
    > for ARCH_FILE in `ls \${ARCH_DIR}`
    > do
    > echo "tar -rvf ${BACKUPFILE2} ${ARCH_DIR}/${ARCH_FILE}" >> ${EXECFILE}
    > done
    > echo " " >> ${EXECFILE}
    >
    > #echo "rm /tmp/ARCHFILES" >> ${EXECFILE}
    >
    > # Restart the redo log archiving process.
    >
    > echo "# Restart the redo log archiving process." >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    > echo "svrmgrl << TOAST" >> ${EXECFILE}
    > echo "connect internal;" >> ${EXECFILE}
    > echo "archive log start;" >> ${EXECFILE}
    > echo "exit;" >> ${EXECFILE}
    > echo "TOAST" >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    >
    > # Verify that the tar commands issued above were successful.
    > # Since tar was issued from within SQL*PLUS, we need to scan the logfile
    > # for error messages.
    >
    > echo "# Verify that the tar commands issued above were successful." >> ${EXECFILE}
    > echo "# Since tar was issued from within SQL*PLUS, we need to scan the logfile"
    > >> ${EXECFILE}

    > echo "# for error messages." >> ${EXECFILE}
    > echo " " >> ${EXECFILE}
    > echo "fgrep -s \"tar:\" ${LOGFILE}" >> ${EXECFILE}
    > echo "tarstatus=\$?" >> ${EXECFILE}
    > echo "if [ \$tarstatus = 0 ]" >> ${EXECFILE}
    > echo "then" >> ${EXECFILE}
    > echo " echo \"${PROGNAME}: tar command unsuccessful.\"" >> ${EXECFILE}
    > echo " echo \"${PROGNAME} exiting at `date`.\"" >> ${EXECFILE}
    > echo " exit ${FAILURE}" >> ${EXECFILE}
    > echo "else" >> ${EXECFILE}
    > echo " echo \"${PROGNAME}: tar commands successful.\"" >> ${EXECFILE}
    > echo "fi" >> ${EXECFILE}
    > echo "echo \"Finished execution of ${EXECFILE} on `date`.\n\"" >> ${EXECFILE}
    >
    > echo "exit" >> ${EXECFILE}
    >
    > # Now make the executable file executable.
    >
    > chmod 740 ${EXECFILE}
    >
    > # Execute the online backup executable file.
    >
    > echo "**** Beginning the online backup on `date` ****" > ${LOGFILE}
    > ${EXECFILE} >> ${LOGFILE} 2>&1
    > echo "**** Completed the online backup on `date` ****" >> ${LOGFILE}
    >
    > echo "Finished executing script ${PROGNAME} on `date`.\n"
    > exit



  3. Re: Backup Script

    sorry .. that's bpbackup


    Karena Angell wrote:

    > After your online backups of the Oracle database is complete, call a netbackup script to
    > execute a backup ( using the bpbkar command -- see the Admin Guide) -- then a class needs to be
    > set up on the backup server that has a User Schedule.
    >
    > Dan Chrastil wrote:
    >
    > > Can the following script be modified to to to netbackup. If so
    > > can someone point me in the right direction.
    > >
    > > #!/usr/bin/sh
    > >
    > > # Run .profile for standard environment
    > > ${HOME}/.profile
    > > TERM=vt100; export TERM
    > > ORAENV_ASK=NO; export ORAENV_ASK
    > > ORACLE_SID=gglp; export ORACLE_SID
    > >
    > > # This script runs the online backups for the Oracle database.
    > > # It takes each database tablespace offline in turn, tars the
    > > # database files to an archive, and then returns the tablespace
    > > # to an online status.
    > >
    > > # Establish the local processing variables.
    > >
    > > PROGNAME=`basename ${0}`
    > > DB_CONNECT_STRING=${1}
    > > NBR_OF_ARGS_PROVIDED=${#}
    > > NBR_OF_ARGS_EXPECTED=1
    > > SQL_CMD=`whence sqlplus`
    > > BACKUPDIR=/kb01/oradata/gglp/backup
    > > BACKUPFILE=${BACKUPDIR}/control_init_backup_`date +%m%d%y`.tar
    > > BACKUPFILE1=${BACKUPDIR}/redo_log_backup_`date +%m%d%y`.tar
    > > BACKUPFILE2=${BACKUPDIR}/archive_log_backup_`date +%m%d%y`.tar
    > > EXECFILE=/tmp/execfile.ksh
    > > LOGDIR=${BACKUPDIR}/logs
    > > LOGFILE=${LOGDIR}/online_backup_`date +%a`.log
    > > SUCCESS=0
    > > FAILURE=1
    > >
    > > # Check for the proper number of input parameters
    > >
    > >
    > > if [ ${NBR_OF_ARGS_PROVIDED} -ne ${NBR_OF_ARGS_EXPECTED} ]
    > >
    > > then
    > >
    > > echo "\nError- improper number of arguments\nUsage: \n\t${PROGNAME} "
    > > exit ${FAILURE}
    > >
    > > fi
    > >
    > >
    > > ################################################## ##################
    > > #
    > > # Back up the database data files.
    > > #
    > > ################################################## ##################
    > >
    > > # Build the list of tablespaces and the associated filenames of each.
    > >
    > > ${SQL_CMD} -s ${DB_CONNECT_STRING} << TOAST
    > >
    > > set echo off;
    > > set feedback off;
    > > set heading off;
    > > set verify off;
    > > set termout off;
    > > set scan off;
    > > set pagesize 0;
    > >
    > > spool /tmp/DATAFILES;
    > >
    > > REM Obtain the files of the tablespaces;
    > >
    > > select tablespace_name || ':' ||
    > > file_name
    > > from dba_data_files
    > > order by
    > > tablespace_name,
    > > file_name;
    > >
    > > spool off;
    > >
    > > REM Build the list of database control files.
    > >
    > > spool /tmp/CONTROLFILES;
    > >
    > > select name
    > > from v\$controlfile
    > > order by
    > > name;
    > >
    > > spool off;
    > >
    > > REM Build the list of database logfiles." >> ${EXECFILE}
    > >
    > > spool /tmp/LOGFILES;
    > >
    > > select member
    > > from v\$logfile
    > > order by
    > > member;
    > >
    > > spool off;
    > >
    > > exit;
    > > TOAST
    > >
    > > # Build the executable script file to perform the online backup.
    > >
    > > echo "#!/bin/ksh" > ${EXECFILE}
    > > echo ". ~oracle/.profile" >> ${EXECFILE}
    > > echo "# Create the tar file to hold the backups." >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > > echo "touch tarseed" >> ${EXECFILE}
    > > echo "tar -cvf ${BACKUPFILE} tarseed" >> ${EXECFILE}
    > > echo "${SQL_CMD} ${DB_CONNECT_STRING} << TOAST" >> ${EXECFILE}
    > > echo "set serveroutput off;" >> ${EXECFILE}
    > > echo "set scan off;" >> ${EXECFILE}
    > >
    > > TAR_SWITCH='0'
    > > PREV_TABLESPACE='FIRST'
    > > for file in `cat /tmp/DATAFILES.lst`
    > > do
    > > TABLESPACE=`echo ${file} | cut -f1 -d":"`
    > > DATAFILE=`echo ${file} | cut -f2 -d":"`
    > > TSBACKUPFILE=${BACKUPDIR}/`basename ${DATAFILE} | cut -f1 -d"."`_backup_`date
    > > +%m%d%y`.tar
    > > if [ ${PREV_TABLESPACE} != ${TABLESPACE} ]
    > > then
    > > if [ ${PREV_TABLESPACE} != 'FIRST' ]
    > > then
    > > echo "alter tablespace ${PREV_TABLESPACE} end backup;" >> ${EXECFILE}
    > > echo "prompt Completed backup of tablespace ${PREV_TABLESPACE} on
    > > " >> ${EXECFILE}
    > > echo "host date;" >> ${EXECFILE}
    > > fi
    > > echo " " >> ${EXECFILE}
    > > echo "REM Backup of tablespace ${TABLESPACE}" >> ${EXECFILE}
    > > echo "REM Datafile ${DATAFILE}" >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > > echo "prompt Beginning backup of tablespace ${TABLESPACE} on " >> ${EXECFILE}
    > > echo "host date;" >> ${EXECFILE}
    > > echo "alter tablespace ${TABLESPACE} begin backup;" >> ${EXECFILE}
    > > PREV_TABLESPACE=${TABLESPACE}
    > > fi
    > > if [ ${TAR_SWITCH} = '0' ]
    > > then
    > > echo "host tar -cvf ${TSBACKUPFILE} ${DATAFILE} &" >> ${EXECFILE}
    > > PREV_TSBACKUPFILE=${TSBACKUPFILE}
    > > TAR_SWITCH='1'
    > > else
    > > echo "host tar -cvf ${TSBACKUPFILE} ${DATAFILE} " >> ${EXECFILE}
    > > TAR_SWITCH='0'
    > > fi
    > > done
    > > echo "alter tablespace ${PREV_TABLESPACE} end backup;" >> ${EXECFILE}
    > > echo "prompt Completed backup of tablespace ${PREV_TABLESPACE} on " >> ${EXECFILE}
    > > echo "host date;" >> ${EXECFILE}
    > >
    > > ################################################## ##################
    > > #
    > > # Back up the database control files.
    > > #
    > > ################################################## ##################
    > >
    > > # Back up the database control files.
    > >
    > > echo " " >> ${EXECFILE}
    > > echo "REM Backing up the control file" >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > > if [ -f ${BACKUPDIR}/controlfile.ctl ]
    > > then
    > > REUSE=reuse
    > > else
    > > REUSE=
    > > fi
    > > echo "alter database backup controlfile to '${BACKUPDIR}/controlfile.ctl'
    > > ${REUSE};" >> ${EXECFILE}
    > >
    > > echo "host tar -rvf ${BACKUPFILE} ${BACKUPDIR}/controlfile.ctl" >> ${EXECFILE}
    > >
    > > echo " " >> ${EXECFILE}
    > > echo "REM Back up the database control files." >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > >
    > > for file in `cat /tmp/CONTROLFILES.lst`
    > > do
    > > echo "host tar -rvf ${BACKUPFILE} ${file}" >> ${EXECFILE}
    > > done
    > >
    > > ################################################## ##################
    > > #
    > > # Back up the database init files.
    > > #
    > > ################################################## ##################
    > >
    > > echo " " >> ${EXECFILE}
    > > echo "REM Back up the database init files." >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > > echo "host tar -rvf ${BACKUPFILE} ${ORACLE_HOME}/dbs/initgglp.ora" >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > >
    > > ################################################## ##################
    > > #
    > > # Back up the database log files.
    > > #
    > > ################################################## ##################
    > >
    > > echo " " >> ${EXECFILE}
    > > echo "REM Back up the database log files." >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > >
    > > for file in `cat /tmp/LOGFILES.lst`
    > > do
    > > echo "host tar -rvf ${BACKUPFILE1} ${file}" >> ${EXECFILE}
    > > done
    > >
    > > # Perform a redo log switch to archive redo logs used during the backup.
    > >
    > > echo " " >> ${EXECFILE}
    > > echo "REM Switching the redo log to back up the redo log used" >> ${EXECFILE}
    > > echo "REM during tablespace backup." >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > > echo "alter system switch logfile;" >> ${EXECFILE}
    > >
    > > echo "exit;" >> ${EXECFILE}
    > > echo "TOAST" >> ${EXECFILE}
    > >
    > > ################################################## ##################
    > > #
    > > # Back up the archived redo log files.
    > > #
    > > ################################################## ##################
    > > # Get the archive log directory.
    > >
    > > svrmgrl << TOAST > /tmp/ARCHFILES
    > > connect internal;
    > > show parameter log_archive_dest;
    > > exit;
    > > TOAST
    > >
    > > # Suspend the redo log archiving process.
    > >
    > > echo " " >> ${EXECFILE}
    > > echo "# Suspend the redo log archiving process." >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > > echo "svrmgrl << TOAST" >> ${EXECFILE}
    > > echo "connect internal;" >> ${EXECFILE}
    > > echo "archive log stop;" >> ${EXECFILE}
    > > echo "exit;" >> ${EXECFILE}
    > > echo "TOAST" >> ${EXECFILE}
    > >
    > > echo " " >> ${EXECFILE}
    > > echo "# Tar the archived redo log files." >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > > ARCH_DIR=`grep log_archive_dest \/tmp\/ARCHFILES | awk '{print \$3}'`
    > > for ARCH_FILE in `ls \${ARCH_DIR}`
    > > do
    > > echo "tar -rvf ${BACKUPFILE2} ${ARCH_DIR}/${ARCH_FILE}" >> ${EXECFILE}
    > > done
    > > echo " " >> ${EXECFILE}
    > >
    > > #echo "rm /tmp/ARCHFILES" >> ${EXECFILE}
    > >
    > > # Restart the redo log archiving process.
    > >
    > > echo "# Restart the redo log archiving process." >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > > echo "svrmgrl << TOAST" >> ${EXECFILE}
    > > echo "connect internal;" >> ${EXECFILE}
    > > echo "archive log start;" >> ${EXECFILE}
    > > echo "exit;" >> ${EXECFILE}
    > > echo "TOAST" >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > >
    > > # Verify that the tar commands issued above were successful.
    > > # Since tar was issued from within SQL*PLUS, we need to scan the logfile
    > > # for error messages.
    > >
    > > echo "# Verify that the tar commands issued above were successful." >> ${EXECFILE}
    > > echo "# Since tar was issued from within SQL*PLUS, we need to scan the logfile"
    > > >> ${EXECFILE}

    > > echo "# for error messages." >> ${EXECFILE}
    > > echo " " >> ${EXECFILE}
    > > echo "fgrep -s \"tar:\" ${LOGFILE}" >> ${EXECFILE}
    > > echo "tarstatus=\$?" >> ${EXECFILE}
    > > echo "if [ \$tarstatus = 0 ]" >> ${EXECFILE}
    > > echo "then" >> ${EXECFILE}
    > > echo " echo \"${PROGNAME}: tar command unsuccessful.\"" >> ${EXECFILE}
    > > echo " echo \"${PROGNAME} exiting at `date`.\"" >> ${EXECFILE}
    > > echo " exit ${FAILURE}" >> ${EXECFILE}
    > > echo "else" >> ${EXECFILE}
    > > echo " echo \"${PROGNAME}: tar commands successful.\"" >> ${EXECFILE}
    > > echo "fi" >> ${EXECFILE}
    > > echo "echo \"Finished execution of ${EXECFILE} on `date`.\n\"" >> ${EXECFILE}
    > >
    > > echo "exit" >> ${EXECFILE}
    > >
    > > # Now make the executable file executable.
    > >
    > > chmod 740 ${EXECFILE}
    > >
    > > # Execute the online backup executable file.
    > >
    > > echo "**** Beginning the online backup on `date` ****" > ${LOGFILE}
    > > ${EXECFILE} >> ${LOGFILE} 2>&1
    > > echo "**** Completed the online backup on `date` ****" >> ${LOGFILE}
    > >
    > > echo "Finished executing script ${PROGNAME} on `date`.\n"
    > > exit



+ Reply to Thread