Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

help backup script

file system
Frequent Advisor

help backup script

Dear experts.

I'm new to the shell script to unix.
can you give me advice.

that script is supposed to execute the oracle backup online.

you can see the backup procedure first 5 lines.
in script.

when i run the script, it has some error
like 'syntax error at line 115: `end of file' unexpected'

I really appreciate to help the script.
so many experts' help is need to do the script

=========
script below

$ cat a.active
######BACKUP STRATEGY##########################################################################
# 1. Copy each tablespace in turn by setting tablespace into hot backup mode , copy the
# tablespace files using unix copy command and then finally releasing the tablespace from
# backup mode.
# 2. Force a log switch .
# 3. copy all the archived log files.
# 4. Backup the control file.
###############################################################################################

#!/usr/bin/ksh
# Get DB info

$ORACLE_HOME/bin/sqlplus /nolog < DB_INFO
connect / as sysdba;
set linesize 200;
select db_unique_name, dbid from v\$database;
select name ||':' || block_size from v\$controlfile;
select file_name ||':'||tablespace_name||':'|| status from dba_data_files
order by tablespace_name;
exit
EOF

#Get DB INFO IN ACT
$ORACLE_HOME/bin/sqlplus /nolog < DB_INFO_ACT
connect / as sysdba;
set linesize 200
set echo off
set head off
select b.file_name||':'||a.status from v\$backup a, dba_data_files b
where a.file#=b.file_id and a.status !='active';
exit
EOF

DB_NAME=`/usr/bin/awk '$2 == "2859985154" { print $1}' DB_INFO`
CONTROLFILE=`/usr/bin/awk -F: '$2 == "16384" { print $1 }' DB_INFO`
DBF_FILE=`/usr/bin/awk -F: '$3 == "AVAILABLE" { print $1 }' DB_INFO`
DBF_FILE_ACT=`/usr/bin/awk -F: '$2 == "NOT ACTIVE" { print $1 }' DB_INFO_ACT`
TABLESPACE_NAME=`/usr/bin/awk -F: '$3 == "AVAILABLE" { print $2 }' DB_INFO`

#PERIPHERAL PARAMETERS################
DATE=`/usr/bin/date +%y%m%d`
BACKUP_HOME=/oracle/backuplog
BACKUP_LOG=${BACKUP_HOME}/`/usr/bin/basename $0 | /usr/bin/cut -d. -f1`.iaeisdb.${DATE}

echo $DB_NAME
echo $CONTROLFILE
echo $DATE
echo $DBF_FILE
echo $DBF_FILE_ACT
echo $TABLESPACE_NAME

########BACKUP DBF_FILE IN TABLESPACE EACH########

for tablespace_name in $TABLESPACE_NAME
do
echo Beginning back up of tablespace ${TABLESPACE_NAME} >> ${BACKUP_LOG}
${ORACLE_HOME}/bin/sqlplus -s </ as sysdba
set heading off feedback off
alter tablespace ${TABLESPACE_NAME} begin backup;
exit
EOF
########BACKUP .DBF IN ACTIVE###############################################
for dbf_file_act in $DBF_FILE_ACT
do
save -s 10.10.10.21 -b oracle -l full $DBF_FILE_ACT
done

echo Finishing back up of tablespace ${TABLESPACE_NAME} >> ${BACKUP_LOG}
${ORACLE_HOME}/bin/sqlplus -s </ as sysdba
set heading off feedback off
alter tablespace ${TABLESPACE_NAME} end backup;

exit 1
EOF
# $TABLESPACE_NAME = $TABLESPACE_NAME_NEXT
# $FILE_NAME = $FILE_NAME_NEXT
done


#if [$TABLESPACE_NAME == $TABLESPACE_NAME_NEXT]
# save -s 10.10.10.21 -b oracle -l full $DBF_FILE_NEXT
#else

#echo Finishing back up of tablespace ${TABLESPACE_NAME} >> ${BACKUP_LOG}
#${ORACLE_HOME}/bin/sqlplus -s < #/ as sysdba
#set heading off feedback off
#alter tablespace ${TABLESPACE_NAME} end backup;

# exit 1
# EOF
#fi
#done

########2.Force a log switch & 3.Copy all the archived log files.##########################
echo Beginning back up of archive log file ${TABLESPACE_NAME} >> ${BACKUP_LOG}
${ORACLE_HOME}/bin/sqlplus -s </ as sysdba
set heading off feedback off
alter system switch log file
exit
EOF
save -s 10.10.10.21 -b oracle -l full /oradata1/Archive

########4. Backup the control file.###############
echo Beginning back up of control file ${TABLESPACE_NAME} >> ${BACKUP_LOG}
${ORACLE_HOME}/bin/sqlplus -s </ as sysdba
set heading off feedback off
alter backup controlfile to ${ORACLE_HOME}/dbs/control.${DATE}
exit
EOF


2 REPLIES
Yogeeraj_1
Honored Contributor

Re: help backup script

hi,

if you are using Oracle 8i or later, please start using Oracle RMAN for backup.

With RMAN, you will just have to run:

RMAN> backup database fileperset 1 plus archivelog delete input.

For more information see also Oracle10g Documentation References:

Oracle Database Backup and Recovery Advanced User's Guide Guide - more information about the recovery catalog>

http://www.oracle.com/pls/db102/to_toc?pathname=backup.102%2Fb14191%2Ftoc.htm&remark=portal+%28Books%29

Oracle® Database Backup and Recovery Reference - CREATE CATALOG command syntax
http://www.oracle.com/pls/db102/to_toc?pathname=backup.102%2Fb14194%2Ftoc.htm&remark=portal+%28Books%29

Oracle Database Backup and Recovery Basics - more information about configuration settings.

http://www.oracle.com/pls/db102/to_toc?pathname=backup.102%2Fb14192%2Ftoc.htm&remark=portal+%28Books%29

More tips on best practices are available in metalink note: 388422.1

hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Peter Godron
Honored Contributor

Re: help backup script

Hi,
can you please:
1. move the #!/usr/bin/ksh to be the first line in the file

2. List all the output you get when you run the script. Do you see:
the $DB_NAME data
the $CONTROLFILE data
the $DATE data
the $DBF_FILE data
the $DBF_FILE_ACT data
the $TABLESPACE_NAME data

Also please provide:
cat ${BACKUP_LOG}
sed -n 115p a.active