If archive logging is enabled one needs to backup archived log files timeously to
prevent database freezes
Etc.
Carefully plan backup retention periods. Ensure enough backup media (tapes) are
available and that old backups are expired in-time to make media available for new
backups. Off-site vaulting is also highly recommended.
Frequently test your ability to recover and document all possible scenarios. Remember,
it's the little things that will get you. Most failed recoveries are a result of organizational
errors and miscommunication.
Cold or Off-line Backups - shut the database down and backup up ALL data, log,
and control files.
RMAN Backups - while the database is off-line or on-line, use the "rman" utility
to backup the database.
It is advisable to use more than one of these methods to backup your database. For
example, if you choose to do on-line database backups, also cover yourself by doing
database exports. Also test ALL backup and recovery scenarios carefully. It is better to be
safe than sorry.
Regardless of your strategy, also remember to backup all required software libraries,
parameter files, password files, etc. If your database is in ARCHIVELOG mode, you also
need to backup archived log files.
A cold (or off-line) backup is a backup performed while the database is off-line and
unavailable to its users. Cold backups can be taken regardless if the database is in
ARCHIVELOG or NOARCHIVELOG mode.
It is easier to restore from off-line backups as no recovery (from archived logs) would be
required to make the database consistent. Nevertheless, on-line backups are less
disruptive and doesn't require database downtime.
Point-in-time recovery (regardless if you do on-line or off-line backups) is only available
when the database is in ARCHIVELOG mode.
[edit] How does one backup a database using the export utility?
Oracle exports are "logical" database backups (not physical) as they extract data and
logical definitions from the database into a file. Other backup strategies normally back-up
the physical data files.
One of the advantages of exports is that one can selectively re-import tables, however
one cannot roll-forward from an restored export. To completely restore a database
from an export file one practically needs to recreate the entire database.
Always do full system level exports (FULL=YES). Full exports include more
information about the database in the export file than user level exports. For more
information about the Oracle export and import utilities, see the Import/ Export FAQ.
Alternatively, add the above commands into your database's startup command script, and
bounce the database.
The following parameters needs to be set for databases in ARCHIVELOG mode:
log_archive_start
log_archive_dest_1
log_archive_dest_state_1
log_archive_format
=
=
=
=
TRUE
'LOCATION=/arch_dir_name'
ENABLE
%d_%t_%s.arc
NOTE 1: Remember to take a baseline database backup right after enabling archivelog
mode. Without it one would not be able to recover. Also, implement an archivelog backup
to prevent the archive log directory from filling-up.
NOTE 2:' ARCHIVELOG mode was introduced with Oracle 6, and is essential for
database point-in-time recovery. Archiving can be used in combination with on-line and
off-line database backups.
NOTE 3: You may want to set the following INIT.ORA parameters when enabling
ARCHIVELOG mode: log_archive_start=TRUE, log_archive_dest=..., and
log_archive_format=...
NOTE 4: You can change the archive log destination of a database on-line with the
ARCHIVE LOG START TO 'directory'; statement. This statement is often used to switch
archiving between a set of directories.
NOTE 5: When running Oracle Real Application Clusters (RAC), you need to shut down
all nodes before changing the database to ARCHIVELOG mode. See the RAC FAQ for
more details.
[edit] I've lost an archived/online REDO LOG file, can I get my DB back?
The following INIT.ORA/SPFILE parameter can be used if your current redologs are
corrupted or blown away. It may also be handy if you do database recovery and one of
the archived log files are missing and cannot be restored.
NOTE: Caution is advised when enabling this parameter as you might end-up losing
your entire database. Please contact Oracle Support before using it.
_allow_resetlogs_corruption = true
This should allow you to open the database. However, after using this parameter your
database will be inconsistent (some committed transactions may be lost or partially
applied).
Steps:
Note that if your database is in ARCHIVELOG mode, one can still use archived log files
to roll forward from an off-line backup. If you cannot take your database down for a cold
(off-line) backup at a convenient time, switch your database into ARCHIVELOG mode
and perform hot (on-line) backups.
It is better to backup tablespace for tablespace than to put all tablespaces in backup mode.
Backing them up separately incurs less overhead. When done, remember to backup your
control files. Look at this example:
ALTER SYSTEM SWITCH LOGFILE;
-- Force log switch to update control
file headers
ALTER DATABASE BACKUP CONTROLFILE TO '/backupDir/control.dbf';
NOTE: Do not run on-line backups during peak processing periods. Oracle will write
complete database blocks instead of the normal deltas to redo log files while in backup
mode. This will lead to excessive database archiving and even database freezes.
If a database was terminated while one of its tablespaces was in BACKUP MODE
(ALTER TABLESPACE xyz BEGIN BACKUP;), it will tell you that media recovery is
required when you try to restart the database. The DBA is then required to recover the
database and apply all archived logs to the database. However, from Oracle 7.2, one can
simply take the individual datafiles out of backup mode and restart the database.
ALTER DATABASE DATAFILE '/path/filename' END BACKUP;
One can select from V$BACKUP to see which datafiles are in backup mode. This
normally saves a significant amount of database down time. See script end_backup2.sql
in the Scripts section of this site.
From Oracle9i onwards, the following command can be used to take all of the datafiles
out of hotbackup mode:
ALTER DATABASE END BACKUP;
This command must be issued when the database is mounted, but not yet opened.
RMAN can do off-line and on-line database backups. It cannot, however, write directly to
tape, but various 3rd-party tools (like Veritas, Omiback, etc) can integrate with RMAN to
handle tape library management.
RMAN can be operated from Oracle Enterprise Manager, or from command line. Here
are the command line arguments:
Argument
Value
Description
---------------------------------------------------------------------------target
quoted-string connect-string for target database
catalog
quoted-string connect-string for recovery catalog
nocatalog
none
if specified, then no recovery catalog
cmdfile
quoted-string name of input command file
log
quoted-string name of output message log file
trace
quoted-string name of output debugging message log file
append
none
if specified, log is opened in append mode
debug
optional-args activate debugging
msgno
none
show RMAN-nnnn prefix for all messages
send
quoted-string send a command to the media manager
pipe
string
building block for pipe names
timeout
integer
number of seconds to wait for pipe input
----------------------------------------------------------------------------
Here is an example:
[oracle@localhost oracle]$ rman
Recovery Manager: Release 10.1.0.2.0 - Production
Copyright (c) 1995, 2004, Oracle. All rights reserved.
RMAN> connect target;
connected to target database: ORCL (DBID=1058957020)
RMAN> backup database;
...
[edit] How does one backup and restore a database using RMAN?
The biggest advantage of RMAN is that it only backup used space in the database.
RMAN doesn't put tablespaces in backup mode, saving on redo generation overhead.
RMAN will re-read database blocks until it gets a consistent image of it. Look at this
simple backup example.
rman target sys/*** nocatalog
run {
allocate channel t1 type disk;
backup
format '/app/oracle/backup/%d_t%t_s%s_p%p'
(database);
release channel t1;
The examples above are extremely simplistic and only useful for illustrating basic
concepts. By default Oracle uses the database controlfiles to store information about
backups. Normally one would rather setup a RMAN catalog database to store RMAN
metadata in. Read the Oracle Backup and Recovery Guide before implementing any
RMAN backups.
Note: RMAN cannot write image copies directly to tape. One needs to use a third-party
media manager that integrates with RMAN to backup directly to tape. Alternatively one
can backup to disk and then manually copy the backups to tape.
[edit] How does one backup and restore archived log files?
One can backup archived log files using RMAN or any operating system backup utility.
Remember to delete files after backing them up to prevent the archive log directory from
filling up. If the archive log directory becomes full, your database will hang! Look at this
simple RMAN backup scripts:
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4>
format '/app/oracle/archback/log_%t_%sp%p'
5>
(archivelog all delete input);
6> release channel dev1;
7> }
The "delete input" clause will delete the archived logs as they are backed-up.
List all archivelog backups for the past 24 hours:
RMAN> LIST BACKUP OF ARCHIVELOG FROM TIME 'sysdate-1';
5> }
Next, log in to rman and create the catalog schema. Prior to Oracle 8i this was done by
running the catrman.sql script.
rman catalog rman/rman
RMAN> create catalog tablespace tools;
RMAN> exit;
You can now continue by registering your databases in the catalog. Look at this example:
rman catalog rman/rman target backdba/backdba
RMAN> register database;
One can also use the "upgrade catalog;" command to upgrade to a new RMAN release, or
the "drop catalog;" command to remove an RMAN catalog. These commands need to be
entered twice to confirm the operation.
[edit] How does one integrate RMAN with third-party Media Managers?
The following Media Management Software Vendors have integrated their media
management software with RMAN (Oracle Recovery Manager):
The above Media Management Vendors will provide first line technical support (and
installation guides) for their respective products.
A complete list of supported Media Management Vendors can be found at:
http://www.oracle.com/technology/deploy/availability/htdocs/bsp.htm
When allocating channels one can specify Media Management spesific parameters. Here
are some examples:
Netbackup on Solaris:
allocate channel t1 type 'SBT_TAPE'
PARMS='SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so.1';
Netbackup on Windows:
allocate channel t1 type 'SBT_TAPE' send
"NB_ORA_CLIENT=client_machine_name";
or:
allocate channel 'dev_1' type 'sbt_tape' parms
'ENV=OB2BARTYPE=Oracle8,OB2APPNAME=orcl,OB2BARLIST=machinename_orcl_arch
logs)';
set
set
set
set
set
newname
newname
newname
newname
newname
for
for
for
for
for
datafile
datafile
datafile
datafile
datafile
1
2
3
4
5
to
to
to
to
to
'/ORADATA/u01/system01.dbf';
'/ORADATA/u02/undotbs01.dbf';
'/ORADATA/u03/users01.dbf';
'/ORADATA/u03/indx01.dbf';
'/ORADATA/u02/example01.dbf';
The above script will connect to the "target" (database that will be cloned), the recovery
catalog (to get backup info), and the auxiliary database (new duplicate DB). Previous
backups will be restored and the database recovered to the "set until time" specified in the
script.
Notes: the "set newname" commands are only required if your datafile names will
different from the target database.
The newly cloned DB will have its own unique DBID.
piece handle=
/
flash_recovery_area/ORCL/backupset/2004_08_20/o1_mf_nnndf_TAG20040820T15
3256_0lczd9tf_.bkp comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current controlfile in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 20-AUG-04
channel ORA_DISK_1: finished piece 1 at 20-AUG-04
piece handle=
/
flash_recovery_area/ORCL/backupset/2004_08_20/o1_mf_ncsnf_TAG20040820T15
3256_0lczfrx8_.bkp comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 20-AUG-04[/code]
Now, let's see if we can restore it. First we need to start the databaase in NOMOUNT
mode:
SQL> startup NOMOUNT
ORACLE instance started.
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
289406976
1301536
262677472
25165824
262144
bytes
bytes
bytes
bytes
bytes</pre>
Now, from SQL*Plus, run the following PL/SQL block to restore the file:
DECLARE
v_devtype
VARCHAR2(100);
v_done
BOOLEAN;
v_maxPieces NUMBER;
TYPE t_pieceName IS TABLE OF varchar2(255) INDEX BY binary_integer;
v_pieceName t_pieceName;
BEGIN
-- Define the backup pieces... (names from the RMAN Log file)
v_pieceName(1) :=
'/flash_recovery_area/ORCL/backupset/2004_08_20/o1_mf_ncsnf_TAG20040820T
153256_0lczfrx8_.bkp';
v_pieceName(2) :=
'/flash_recovery_area/ORCL/backupset/2004_08_20/o1_mf_nnndf_TAG20040820T
153256_0lczd9tf_.bkp';
v_maxPieces
:= 2;
-- Allocate a channel... (Use type=>null for DISK, type=>'sbt_tape'
for TAPE)
v_devtype := DBMS_BACKUP_RESTORE.deviceAllocate(type=>NULL,
ident=>'d1');
-- Restore the first Control File...
DBMS_BACKUP_RESTORE.restoreSetDataFile;
-- CFNAME mist be the exact path and filename of a controlfile taht
was backed-up
DBMS_BACKUP_RESTORE.restoreControlFileTo(cfname=>'/app/oracle/oradata/or
cl/control01.ctl');
dbms_output.put_line('Start restoring '||v_maxPieces||' pieces.');
FOR i IN 1..v_maxPieces LOOP
dbms_output.put_line('Restoring from piece '||v_pieceName(i));
DBMS_BACKUP_RESTORE.restoreBackupPiece(handle=>v_pieceName(i),
done=>v_done, params=>null);
exit when v_done;
END LOOP;
-- Deallocate the channel...
DBMS_BACKUP_RESTORE.deviceDeAllocate('d1');
EXCEPTION
WHEN OTHERS THEN
DBMS_BACKUP_RESTORE.deviceDeAllocate;
RAISE;
END;
/