René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback
 

A shell script for a cold backup in Oracle

This shell script selects the datafiles, logfiles and control files, tars and gzips them and then sends them to a remote host via rsh.
TNS_ADMIN=/export/opt/oracle/8.1.7/network/admin
export TNS_ADMIN

ORACLE_SID=some_sid
export ORACLE_SID

ORACLE_HOME=/export/opt/oracle/8.1.7
export ORACLE_HOME

DT=`date +%Y.%m.%d`

PFILE=/export/opt/oracle/8.1.7/dbs/init$ORACLE_SID.ora

echo
echo Backup for $DT
echo Selecting the files that must be backed up....
echo

/export/opt/oracle/8.1.7/bin/sqlplus -S '/ as sysdba' <<EOFSQL

set termout off
set pages 0
set lines 120
set feedback off
set trimspool on

spool files.2.backup

select name   from v$datafile;
select name   from v$controlfile;
select member from v$logfile;
select '$PFILE' from dual;

spool off

shutdown immediate

exit;

EOFSQL


echo
echo now taring...
echo

tar cfv - -I files.2.backup | gzip | rsh -l some_user some_host "cat - > /path/to/destdir/backup-$DT.tar.gz"

/export/opt/oracle/8.1.7/bin/sqlplus -S '/ as sysdba' <<EOFSQL
startup pfile=$PFILE
exit;
EOFSQL