
Installgen
Features and Benefits
Installgen
Demo Available for download...
Bookmark This Page

#!/bin/sh
# script: prod1_open_db_backup_job_1.sh (renamed from 33_sol_prod1_open_db_backup_job_1.sh)
# Features: This shell script creates a sql script which performs an
# open database backup to the /backup location. It then
# executes the sql script it builds in order to perform the
# backup.
# This script builds the open database restore shell script when it builds
# the shell script for the backup.
# This script also backs up the init.ora, orapw, vfstab, alert.log,
# backup and restore scripts and creates the prod1_disaster_recovery.txt file.
# A DBVERIFY is performed on each of the backup files created
# during the backup process.
# Note: This script only needs scheduled via a CRON job if the same task has not
# been scheduled via a OEM job.
#
# Script Sequence#: 33
# Used By: CRON job via oracle UNIX account
# Usage:
# ******** Open Oracle Database backup nightly at 4:03 ********
# 03 4 * * 0-6 /opt/server_scripts/prod1_open_db_backup_job_1.sh
# Copyright 2002 by .com Solutions Inc.
#
# ---------------------- Revision History ---------------
# Date By Changes
# 10-7-2001 dsimpson Initial Release
# 05-10-2002 dsimpson Updated to use oracle UNIX account.
# 10-14-2002 dsimpson Updated for use with Mac OS X.
# 11-02-2002 dsimpson Corrected pathname to DBV.
# This output file was created by Installgen version 1.38 on Sun Nov 10 14:20:50 2002. By .com Solutions Inc. www.dotcomsolutionsinc.net
# define globally used paths/variables
ORACLE_BASE=/u01/v901
ORACLE_HOME=/u01/v901
ORACLE_OWNER=oracle
ORACLE_OWNER_PATH=/export/oracle
ORACLE_GROUP=dba
ORACLE_HOME=/u01/v901
ORACLE_SID=prod1
LD_LIBRARY_PATH=/u01/v901/lib:/u01/v901/lib64:/usr/dt/lib
CLASSPATH=$ORACLE_HOME/jdbc/lib/classes111.zip
ORAENV_ASK=NO
TNS_ADMIN=$ORACLE_HOME/network/admin
PATH=/usr/sbin/:/bin:/usr/bin:/usr/ccs/bin:/usr/ucb/bin:/usr/ucb:/usr/openwin/bin:/usr/dt/bin:/usr/local/bin:/opt/bin:/usr/opt/SUNWmd/sbin:/usr/platform/sun4u/sbin:/opt/sfw/bin:.:/usr/local/sbin:/u01/v901/bin
TERM=vt100
NLS_LANG=AMERICAN_AMERICA.US7ASCII
export ORACLE_OWNER ORACLE_OWNER_PATH ORACLE_GROUP ORACLE_HOME ORACLE_SID ORA_BDUMP_DIR LD_LIBRARY_PATH PATH ORAENV_ASK TNS_ADMIN TERM NLS_LANG
# write the SQL file which obtains the list of datafiles for backup
exec 3>/opt/server_scripts/prod1_open_db_backup_files_get_1.sql
echo "-- script: prod1_open_db_backup_files_get_1.sql">&3
echo "-- Features: This sql script obtains a list of files to be backed up. ">&3
echo "-- Output File: prod1_open_db_backup_files_1.sql">&3
echo "--">&3
echo "-- Copyright 2002 by .com Solutions Inc.">&3
echo "--">&3
echo "-- ---------------------- Revision History ---------------">&3
echo "-- Date By Changes">&3
echo "-- 10-7-2001 dsimpson Initial Release">&3
echo " ">&3
echo "set echo off">&3
echo "set feedback off">&3
echo "set verify off">&3
echo "set pagesize 0">&3
echo "set linesize 150">&3
echo "spool /opt/server_scripts/prod1_open_db_backup_files_1.sql">&3
echo "select '-- script: prod1_open_db_backup_files_1.sql ' from dual;">&3
echo "select '-- Features: This sql script performs an open database backup to' from dual;">&3
echo "select '-- the /backup location. ' from dual;">&3
echo "select '-- Each backed up datafile is checked with DBVERIFY ' from dual;">&3
echo "select '-- after it is copied to the /backup location. ' from dual;">&3
echo "select '-- ' from dual;">&3
echo "select '-- Used By: executed by 33_sol_prod1_open_db_backup_job_1.sh ' from dual;">&3
echo "select '-- ' from dual;">&3
echo "select '-- Copyright 2002 by .com Solutions Inc. ' from dual;">&3
echo "select '-- ' from dual;">&3
echo "select '-- ---------------------- Revision History --------------- ' from dual;">&3
echo "select '-- Date By Changes ' from dual;">&3
echo "select '-- 10-7-2001 dsimpson Initial Release ' from dual;">&3
echo "select '-- ' from dual;">&3
echo "select 'set echo on ' from dual;">&3
echo "select 'ALTER TABLESPACE ' || t.name || ' BEGIN BACKUP;' || CHR(10)">&3
echo "|| 'host cp ' || f.name || ' /backup/prod1_' || substr(f.name,instr(f.name,'/',-1,1)+1) || CHR(10)">&3
echo "|| 'ALTER TABLESPACE ' || t.name || ' END BACKUP;' || CHR(10)">&3
echo "|| 'ALTER SYSTEM ARCHIVE LOG CURRENT;' || CHR(10)">&3
echo "from V\$TABLESPACE t, V\$DATAFILE f where t.ts# = f.ts# order by t.name;">&3
echo "select ' ' from dual;">&3
echo "select '-- check each backed up datafile with DBVERIFY' from dual;">&3
echo "select 'host /u01/v901/bin/dbv file=/backup/prod1_' || substr(name,instr(name,'/',-1,1)+1) || ' blocksize=16384 logfile=prod1_' || substr(name,instr(name,'/',-1,1)+1) || '_dbverify.log' from V\$DATAFILE;">&3
echo "select 'host mv prod1_' || substr(name,instr(name,'/',-1,1)+1) || '_dbverify.log' || ' /backup' from V\$DATAFILE;">&3
echo "select 'host cat /backup/prod1_' || substr(name,instr(name,'/',-1,1)+1) || '_dbverify.log' from V\$DATAFILE;">&3
echo "spool off">&3
# write the SQL file which obtains the list of datafiles for restore
exec 3>/opt/server_scripts/prod1_open_db_restore_files_get_1.sql
echo "-- script: prod1_open_db_restore_files_get_1.sql">&3
echo "-- Features: This sql script obtains a list of files to be restored. ">&3
echo "-- Output File: prod1_open_db_restore_files_1.sh">&3
echo "--">&3
echo "-- Copyright 2002 by .com Solutions Inc.">&3
echo "--">&3
echo "-- ---------------------- Revision History ---------------">&3
echo "-- Date By Changes">&3
echo "-- 10-7-2001 dsimpson Initial Release">&3
echo " ">&3
echo "set echo off">&3
echo "set feedback off">&3
echo "set verify off">&3
echo "set pagesize 0">&3
echo "set linesize 150">&3
echo "spool /opt/server_scripts/prod1_open_db_restore_files_1.sql">&3
echo "select '#!/bin/sh ' from dual;">&3
echo "select '# script: prod1_open_db_restore_files_1.sql ' from dual;">&3
echo "select '# Features: This shell script performs an open database restore from' from dual;">&3
echo "select '# the /backup location. ' from dual;">&3
echo "select '# Notes: This entire script should not normally be run.' from dual;">&3
echo "select '# Comment out the unneeded statements in order to restore' from dual;">&3
echo "select '# a subset of the database files which have been lost or damaged.' from dual;">&3
echo "select '# The database should be shut down when performing the restore.' from dual;">&3
echo "select '# ' from dual;">&3
echo "select '# Used By: executed manually from the oracle UNIX account' from dual;">&3
echo "select '# ' from dual;">&3
echo "select '# Copyright 2002 by .com Solutions Inc. ' from dual;">&3
echo "select '# ' from dual;">&3
echo "select '# ---------------------- Revision History --------------- ' from dual;">&3
echo "select '# Date By Changes ' from dual;">&3
echo "select '# 10-7-2001 dsimpson Initial Release ' from dual;">&3
echo "select ' ' from dual;">&3
echo "select '# define globally used paths/variables' from dual;">&3
echo "select 'ORACLE_BASE=/u01/v901' from dual;">&3
echo "select 'ORACLE_HOME=/u01/v901' from dual;">&3
echo "select 'ORACLE_OWNER=oracle' from dual;">&3
echo "select 'ORACLE_OWNER_PATH=/export/oracle' from dual;">&3
echo "select 'ORACLE_GROUP=dba' from dual;">&3
echo "select 'PATH=/usr/sbin/:/bin:/usr/bin:/usr/ccs/bin:/usr/ucb/bin:/usr/ucb:/usr/openwin/bin:/usr/dt/bin:/usr/local/bin:/opt/bin:/usr/opt/SUNWmd/sbin:/usr/platform/sun4u/sbin:/opt/sfw/bin:.:/usr/local/sbin:/u01/v901/bin' from dual;">&3
echo "select 'ORACLE_SID=prod1' from dual;">&3
echo "select 'CLASSPATH=/u01/v901/jdbc/lib/classes111.zip' from dual;">&3
echo "select 'LD_LIBRARY_PATH=/u01/v901/lib:/u01/v901/lib64:/usr/dt/lib' from dual;">&3
echo "select 'ORAENV_ASK=NO' from dual;">&3
echo "select 'TNS_ADMIN=/u01/v901/network/admin' from dual;">&3
echo "select 'TERM=vt100' from dual;">&3
echo "select 'NLS_LANG=AMERICAN_AMERICA.US7ASCII' from dual;">&3
echo "select 'USER=oracle ' from dual;">&3
echo "select '# ' from dual;">&3
echo "select 'export ORACLE_OWNER ORACLE_OWNER_PATH ORACLE_GROUP ORACLE_HOME ORACLE_SID ORA_BDUMP_DIR LD_LIBRARY_PATH PATH ORAENV_ASK TNS_ADMIN TERM NLS_LANG' from dual;">&3
echo "select '# ' from dual;">&3
echo "select ' ' from dual;">&3
echo "select '# make sure the oracle user is running this script' from dual;">&3
echo "select 'if [ ! $LOGNAME = "$ORACLE_OWNER" ] ' from dual;">&3
echo "select 'then' from dual;">&3
echo "select ' # the user running this script is not $ORACLE_OWNER - exit' from dual;">&3
echo "select ' echo "You must be logged in as the $ORACLE_OWNER user to run this script, exiting...."' from dual;">&3
echo "select ' # exit immediately!' from dual;">&3
echo "select ' exit' from dual;">&3
echo "select 'fi' from dual;">&3
echo "select 'cp /backup/prod1_' || substr(name,instr(name,'/',-1,1)+1) || ' ' || name from V\$DATAFILE">&3
echo "union">&3
echo "select 'cp /backup/prod1_' || substr(member,instr(member,'/',-1,1)+1) || ' ' || member from V\$LOGFILE">&3
echo "union">&3
echo "select 'cp /backup/prod1_' || substr(name,instr(name,'/',-1,1)+1) || ' ' || name from V\$CONTROLFILE;">&3
echo "spool off">&3
# write the SQL file which obtains the list of disaster recovery info
FORMAT_VAR=\'99,999,990.90\';
TS_FREE='SM$TS_FREE'
TS_AVAIL='SM$TS_AVAIL'
exec 3>/opt/server_scripts/prod1_disaster_recovery_get.sql
echo "set echo off">&3
echo "set feedback off">&3
echo "set verify off">&3
echo "set pagesize 0">&3
echo "set linesize 100">&3
echo "spool /backup/prod1_disaster_recovery.txt">&3
echo "select '-- file: prod1_disaster_recovery.txt ' from dual;">&3
echo "select '-- Features: This text file provides a listing of tablespaces' from dual;">&3
echo "select '-- data file names,sizes and user account info. ' from dual;">&3
echo "select '-- ' from dual;">&3
echo "select '-- Used By: DBA for disaster recovery purposes ' from dual;">&3
echo "select '-- ' from dual;">&3
echo "select '-- Copyright 2002 by .com Solutions Inc. ' from dual;">&3
echo "select '-- ' from dual;">&3
echo "select '-- ---------------------- Revision History --------------- ' from dual;">&3
echo "select '-- Date By Changes ' from dual;">&3
echo "select '-- 10-6-2001 dsimpson Initial Release ' from dual;">&3
echo "select ' ' from dual;">&3
echo "select 'Report produced on: ' || sysdate from dual;">&3
echo "select 'Database name: prod1' from dual;">&3
echo "select 'Database server hostname: blade1' from dual;">&3
echo "select ' ' from dual;">&3
echo "select 'Tablespace' || 'File' || CHR(9) || CHR(9) || CHR(9) || CHR(9) || 'Size (bytes)' from dual;">&3
echo "select tablespace_name || CHR(9) || CHR(9) || file_name || CHR(9) || CHR(9) || bytes from dba_data_files order by tablespace_name;">&3
echo "select ' ' from dual;">&3
echo "select 'Username' || CHR(9) || 'Status' || CHR(9) || 'Tablespace'|| CHR(9) || 'Temp' || CHR(9) || 'Created' from dual;">&3
echo "select username || CHR(9) || CHR(9) || account_status || CHR(9) || default_tablespace || CHR(9) || CHR(9) || temporary_tablespace || CHR(9) || created from dba_users order by username;">&3
echo "select ' ' from dual;">&3
echo "select 'Tablespace' || CHR(9) || CHR(9) || CHR(9) || 'Status' || CHR(9) || CHR(9) || 'Size (Mb)' || CHR(9) || 'Used (Mb)' || CHR(9) || 'Free (Mb)' from dual;">&3
echo "SELECT D.TABLESPACE_NAME,D.STATUS,TO_CHAR((A.BYTES/1024/1024),$FORMAT_VAR),TO_CHAR(((A.BYTES-DECODE(F.BYTES,NULL,0,F.BYTES))/1024/1024),$FORMAT_VAR),TO_CHAR(((A.BYTES/1024/1024)-(A.BYTES-DECODE(F.BYTES,NULL,0,F.BYTES))/1024/1024),$FORMAT_VAR) FROM DBA_TABLESPACES D,SYS.$TS_AVAIL A,SYS.$TS_FREE F WHERE D.TABLESPACE_NAME = A.TABLESPACE_NAME AND F.TABLESPACE_NAME(+)=D.TABLESPACE_NAME;">&3
echo "spool off">&3
#su - oracle -c "$ORACLE_HOME/bin/sqlplus /nolog"<< EOF
$ORACLE_HOME/bin/sqlplus /nolog << EOF
connect / as SYSDBA
set echo off
-- perform an inconsistent backup of the controlfile
-- using this binary control file requires an OPEN RESETLOGS
-- delete existing file if it exists
host rm /backup/prod1_control01.ctl_bk
ALTER DATABASE BACKUP CONTROLFILE TO '/backup/prod1_control01.ctl_bk';
-- temporarily change the user dump dest so that
-- the text copy of the control file rebuilding sql commands
-- go into the /backup directory
ALTER SYSTEM SET USER_DUMP_DEST='/backup';
ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
ALTER SYSTEM SET USER_DUMP_DEST='/u01/udump';
-- get list of datafiles for sql backup script
@/opt/server_scripts/prod1_open_db_backup_files_get_1.sql
-- get list of datafiles for restore shell script
@/opt/server_scripts/prod1_open_db_restore_files_get_1.sql
-- output the disaster recovery info to /backup/prod1_disaster_recovery.txt
@/opt/server_scripts/prod1_disaster_recovery_get.sql
-- perform the actual backup and check the files with DBVERIFY
@/opt/server_scripts/prod1_open_db_backup_files_1.sql
set echo on
set feedback on
set verify on
set pagesize 24
exit;
EOF
# make a copy of /etc/vfstab into /backup directory
cp /etc/vfstab /backup/etc_vfstab
# make a copy of alert.log file into /backup directory
cp /u01/bdump/alert_prod1.log /backup
# set ownership of .sql files to oracle account
chown $ORACLE_OWNER:$ORACLE_GROUP /opt/server_scripts/prod1_open_db_backup_files_get_1.sql
chown $ORACLE_OWNER:$ORACLE_GROUP /opt/server_scripts/prod1_open_db_restore_files_get_1.sql
# make the shell scripts executable
chmod +x /opt/server_scripts/*.sh
# make backup copies of the backup scripts so that they get put onto tape
cp /opt/server_scripts/prod1_open_db_backup_files_get_1.sql /backup
cp /opt/server_scripts/prod1_open_db_restore_files_get_1.sql /backup
cp /opt/server_scripts/prod1_open_db_backup_files_1.sql /backup
cp /opt/server_scripts/prod1_open_db_restore_files_1.sql /backup
# make a backup copy of the init.ora file
cp $ORACLE_HOME/dbs/initprod1.ora /backup/initprod1.ora
# make a backup copy of the orapwd file
cp $ORACLE_HOME/dbs/orapw /backup/prod1_orapw
# set file ownership of the copied files to the
# oracle UNIX account (otherwise they will be owned by root)
# chown $ORACLE_OWNER:$ORACLE_GROUP /backup/*

