Wednesday, November 17, 2010

2 minutes full off-line Database backup using Volume Snapshot

If you use a good Network Storage system, certified with Oracle and for simplicity mount Oracle home and datafiles to NFS volumes, you can make offline backups in less than 5 minutes...

You will :
1/. Shutdown the database
2/. Snapshot the NFS volume on the storage system (StorageName) where Oracle home is located.
    This can also be done if datafiles, archlogs, etc.. are a distinct volume on the Storage.
3/. Restart the database

The snapshot can be mirrored to a DR Storage System and/or backed up to Tape.

Database down,snap & up script (backuporacle.sh)

ORACLE_HOME=/u01/app/oracle/orahome/mydbase
LD_LIBRARY_PATH=$ORACLE_HOME/lib
PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch
ORACLE_SID=mydbase
export ORACLE_HOME
export ORACLE_SID
export PATH
export LD_LIBRARY_PATH
echo Shutting down the database
echo ------------------------------------
/u01/app/oracle/orahome/mydbase/bin/lsnrctl stop<<EOF
EOF
/u01/app/oracle/orahome/mydbase/bin/sqlplus /nolog<<EOF
connect / as sysdba
shutdown immediate
EOF
echo Filer Snapshots - delete day-2 Oracle home volume snapshot (oraHprev),
echo rename day-1 to oraHprev and snap (oraHsnap).
echo ------------------------------------
/usr/bin/rsh StorageName -l rootaccount:rootpassword snap delete orahome oraHprev
/usr/bin/rsh StorageName -l rootaccount:rootpassword snap rename orahome oraHsnap oraHprev
/usr/bin/rsh StorageName -l rootaccount:rootpassword snap create orahome oraHsnap
echo Removing archived logs in both paths
echo ------------------------------------
/bin/rm /u01/app/oracle/Archlogs/arch*.arc
/bin/rm /u01/app/oracle/exports/Archlogs/arch*.arc
echo Restarting the database
echo ------------------------------------
/u01/app/oracle/orahome/mydbase/bin/lsnrctl start<<EOF
EOF
/u01/app/oracle/orahome/mydbase/bin/sqlplus /nolog<<EOF
connect / as sysdba
startup
EOF


Linux cron file to execute the backup script for example at 23h30, Monday to Friday (1-5) :
(2 single lines, no line break)

29 23 * * 1-5 /bin/echo Shutdown the database, rename snapshots, create snapshots, startup the database >> /u01/app/oracle/BUPScripts/backup.log

30 23 * * 1-5 /u01/app/oracle/BUPScripts/backuporacle.sh 1>> /u01/app/oracle/BUPScripts/backup.log 2>&1

No comments:

Post a Comment