mercoledì 9 aprile 2008

Oracle DB: Cold backup

A cold backup is a phisical backup and is done with the database in a shutdown state (not available to users).
The datafiles do not change during the copy so the database is in sync upon restore.

First of all, you need to shutdown your instance:

export TNS_ADMIN=/export/opt/oracle/8.1.7/network/admin
export ORACLE_SID=some_sid
export ORACLE_HOME=/export/opt/oracle/8.1.7

DT=`date +%Y.%m.%d`
PFILE=/export/opt/oracle/8.1.7/dbs/init$ORACLE_SID.ora

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

/export/opt/oracle/8.1.7/bin/sqlplus -S '/ as sysdba' [minor][minor]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


then you should "tar" your datafiles, controlfiles and logfiles (so called "image copy"):

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


or you can direclty tar a folder; the following is an example on linux:

tar -zcvf ASRAC_20080409_00.tar.gz ASRAC /hera01/app/oracle/oradata/ASRAC

finally startup you instance:

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