Oracle Database Backup and Recovery
Oracle Database Backup and Recovery
Oracle Database Backup and Recovery
RMAN> run {
set until time to_date('04-Aug-2004 00:00:00', 'DD-MON-YYYY HH24:MI:SS');
restore database;
recover database;
}
http://www.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ 1/12
16/12/2017 Oracle database Backup and Recovery FAQ - Oracle FAQ
This is probably not the appropriate time to be sarcastic, but, recovery without backups are not supported. You know that you should have tested your recovery strategy,
and that you should always backup a corrupted database before attempting to restore/recover it.
Nevertheless, Oracle Consulting can sometimes extract data from an offline database using a utility called DUL (Disk UnLoad - Life is DUL without it!). This utility reads
data in the data files and unloads it into SQL*Loader or export dump files. Hopefully you'll then be able to load the data into a working database.
Note that DUL does not care about rollback segments, corrupted blocks, etc, and can thus not guarantee that the data is not logically corrupt. It is intended as an absolute
last resort and will most likely cost your company a lot of money!
DUDE (Database Unloading by Data Extraction) is another non-Oracle utility that can be used to extract data from a dead database. More info about DUDE is available
at http://www.ora600.nl/ .
How does one backup a database using the export utility? [edit]
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 = TRUE
log_archive_dest_1 = 'LOCATION=/arch_dir_name'
log_archive_dest_state_1 = ENABLE
log_archive_format = %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=...
http://www.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ 2/12
16/12/2017 Oracle database Backup and Recovery FAQ - Oracle FAQ
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.
I've lost an archived/online REDO LOG file, can I get my DB back? [edit]
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:
Do a "SHUTDOWN NORMAL" of the database
Set the above parameter
Do a "STARTUP MOUNT" and "ALTER DATABASE OPEN RESETLOGS;"
If the database asks for recovery, use an UNTIL CANCEL type recovery and apply all available archive and on-line redo logs, then issue CANCEL and reissue the
"ALTER DATABASE OPEN RESETLOGS;" command.
Wait a couple of minutes for Oracle to sort itself out
Do a "SHUTDOWN NORMAL"
Remove the above parameter!
Do a database "STARTUP" and check your ALERT.LOG file for errors.
Extract the data and rebuild the entire database
Sometimes Oracle takes forever to shutdown with the "immediate" option. As workaround to this problem, shutdown using these commands:
http://www.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ 3/12
16/12/2017 Oracle database Backup and Recovery FAQ - Oracle FAQ
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.
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 Scriptssection of this site.
From Oracle9i onwards, the following command can be used to take all of the datafiles out of hotbackup mode:
This command must be issued when the database is mounted, but not yet opened.
Here is an example:
http://www.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ 5/12
16/12/2017 Oracle database Backup and Recovery FAQ - Oracle FAQ
How does one backup and restore a database using RMAN? [edit]
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.
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.
How does one backup and restore archived log files? [edit]
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:
http://www.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ 6/12
16/12/2017 Oracle database Backup and Recovery FAQ - Oracle FAQ
RMAN> run {
2> allocate channel dev1 type disk;
3> restore (archivelog low logseq 78311 high logseq 78340 thread 1 all);
4> release channel dev1;
5> }
sqlplus sys
SQL> create user rman identified by rman;
SQL> alter user rman default tablespace tools temporary tablespace temp;
SQL> alter user rman quota unlimited on tools;
SQL> grant connect, resource, recovery_catalog_owner to rman;
SQL> exit;
Next, log in to rman and create the catalog schema. Prior to Oracle 8i this was done by running the catrman.sql script.
You can now continue by registering your databases in the catalog. Look at this example:
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.
How does one integrate RMAN with third-party Media Managers? [edit]
The following Media Management Software Vendors have integrated their media management software with RMAN (Oracle Recovery Manager):
Veritas NetBackup - http://www.veritas.com/
EMC Data Manager (EDM) - http://www.emc.com/
HP OMNIBack/ DataProtector - http://www8.hp.com/us/en/software-solutions/data-protector-backup-recovery-software/
IBM's Tivoli Storage Manager (formerly ADSM) - http://www.tivoli.com/storage/
EMC Networker - http://www.emc.com/
http://www.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ 7/12
16/12/2017 Oracle database Backup and Recovery FAQ - Oracle FAQ
Netbackup on Windows:
or:
http://www.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ 8/12
16/12/2017 Oracle database Backup and Recovery FAQ - Oracle FAQ
run {
set newname for datafile 1 to '/ORADATA/u01/system01.dbf';
set newname for datafile 2 to '/ORADATA/u02/undotbs01.dbf';
set newname for datafile 3 to '/ORADATA/u03/users01.dbf';
set newname for datafile 4 to '/ORADATA/u03/indx01.dbf';
set newname for datafile 5 to '/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.
Can one restore RMAN backups without a CONTROLFILE and RECOVERY CATALOG? [edit]
Details of RMAN backups are stored in the database control files and optionally a Recovery Catalog. If both these are gone, RMAN cannot restore the database. In such a
situation one must extract a control file (or other files) from the backup pieces written out when the last backup was taken. Let's look at an example:
Let's take a backup (partial in our case for ilustrative purposes):
http://www.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ 9/12
16/12/2017 Oracle database Backup and Recovery FAQ - Oracle FAQ
channel ORA_DISK_1: finished piece 1 at 20-AUG-04
piece handle=
/flash_recovery_area/ORCL/backupset/2004_08_20/o1_mf_ncsnf_TAG20040820T153256_0lczfrx8_.bkp comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 20-AUG-04
Now, let's see if we can restore it. First we need to start the databaase in NOMOUNT mode:
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;
-- CFNAME mist be the exact path and filename of a controlfile taht was backed-up
DBMS_BACKUP_RESTORE.restoreControlFileTo(cfname=>'/app/oracle/oradata/orcl/control01.ctl');
SQL> ! ls -l /oradata/orcl/control01.ctl
-rw-r----- 1 oracle dba 3096576 Aug 20 16:45 /oradata/orcl/control01.ctl
Database altered.
Database altered.
http://www.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ 11/12
16/12/2017 Oracle database Backup and Recovery FAQ - Oracle FAQ
See Metalink Note 60545.1 for detailed examples.
http://www.orafaq.com/wiki/Oracle_database_Backup_and_Recovery_FAQ 12/12