4.3.1 Making Consistent and Inconsistent Backups With RMAN
4.3.1 Making Consistent and Inconsistent Backups With RMAN
Any backup taken when the database has not been shut down normally is
an inconsistent backup. When a database is restored from an inconsistent backup,
Oracle must perform media recovery before the database can be opened, applying any
pending changes from the redo logs.
As long as your database is running in ARCHIVELOG mode, and you back up your archived
redo log files as well as your datafiles, inconsistent backups can be the foundation for a
sound backup and recovery strategy. Inconsistent backups are an important part of the
backup strategy for most databases, because they offer superior availability. For
example, backups taken while the database is still open are inconsistent backups.
Note:
When performing user-managed backups, taking online backups required that you place
your datafiles into backup mode using the ALTER DATABASE/TABLESPACE BEGIN
BACKUP statement. RMAN does not require the use of backup mode for the creation of
online backups. Do not use ALTER DATABASE/TABLESPACE BEGIN BACKUP before an RMAN
backup.
You can perform whole database backups with the database mounted or open. To
perform a whole database backup, from the RMAN prompt, use
the BACKUP DATABASEcommand. The simplest form of the command requires no
parameters, as shown in this example:
This example shows the procedure for taking a whole database backup to the default
destination:
To back up a tablespace:
You can back up datafiles and datafile copies when the database is mounted or open.
4.3.4.1 Backing Up Datafiles
You can back up the control file when the database is mounted or open. RMAN uses a
snapshot control file to ensure a read-consistent
version. If CONFIGURE CONTROLFILEAUTOBACKUP is ON (by default it is OFF), then RMAN
automatically backs up the control file and server parameter file after every backup and
after database structural changes. The control file autobackup contains metadata about
the previous backup, which is crucial for disaster recovery.
If the autobackup feature is not set, then you must manually back up the control file in
one of the following ways:
Run BACKUP CURRENT CONTROLFILE
Include a backup of the control file within any backup by using
the INCLUDE CURRENT CONTROLFILE option of the BACKUP command
Back up datafile 1, because RMAN automatically includes the control file and
SPFILE in backups of datafile 1
Note:
If the control file block size is not the same as the block size for
datafile 1, then the control file cannot be written into the same
backup set as the datafile. RMAN writes the control file into a
backup set by itself if the block size is different.
A manual backup of the control file is not the same as a control file autobackup. In
manual backups, only RMAN repository data for backups within the current RMAN
session is in the control file backup, and a manually backed-up control file cannot be
automatically restored.
See Also:
Oracle Database Backup and Recovery Advanced User's Guide to learn more about
control file autobackups
If the autobackup feature is enabled, then RMAN also creates an autobackup of the
control file after the BACKUP TABLESPACE command completes, so that the control file
autobackup contains the record of the backup that was taken.
If the control file autobackup feature is enabled, then RMAN makes two control file
backups in this example: the explicit control file backup (BACKUP CURRENT CONTROLFILE) and
the autobackup of the control file and server parameter file.
As explained in "Backing Up Control Files with RMAN", RMAN automatically backs up the
current server parameter file in certain cases. The BACKUP SPFILE command backs up the
parameter file explicitly. For example:
The SPFILE that is backed up is the one currently in use by the instance. If the instance
is started with a client-side initialization parameter file, then RMAN does not back up
anything when this command is used.
4.3.7 Backing Up Archived Redo Logs with RMAN
Archived redo logs are the key to successful media recovery. Back them up regularly.
You can back up logs with BACKUP ARCHIVELOG, or back up logs while backing up datafiles
and control files by specifying BACKUP ... PLUS ARCHIVELOG.
Even if your redo logs are being archived to multiple destinations and you use RMAN to
back up archived redo logs, RMAN selects only one copy of the archived redo log file to
include in the backup set. (Since logs with the same log sequence number are identical,
there is no need to include more than one copy.)
You can also specify a range of archived redo logs by time, SCN, or log sequence
number, as in the following example:
BACKUP ARCHIVELOG
FROM TIME 'SYSDATE-30' UNTIL TIME 'SYSDATE-7';
When taking a backup of archived redo logs that includes the most recent log (that is,
a BACKUP ... ARCHIVELOG command is run without the UNTIL or SEQUENCE option) if the
database is open, then before beginning the backup, RMAN will switch out of the
current online redo log group, and all online redo logs that have not yet been archived,
up to and including the redo log group that was current when the command was
issued. This ensures that the backup contains all redo that was generated prior to the
start of the command.
In this case RMAN backs up only one copy of each log sequence number in these
directories, and then deletes all copies of any log that it backed up from the archiving
destinations. If you had specified DELETE INPUT rather than DELETE ALL INPUT, then RMAN
would only delete the specific archived redo log files that it backed up (for example, it
would delete the archived redo log files in /arc_dest1 if those were the files used as the
source of the backup, but it would leave the contents of
the/arc_dest2 and /arc_dest3 intact) .
You can add archived redo logs to a backup of other files by using
the BACKUP ... PLUS ARCHIVELOG clause. Adding BACKUP ... PLUS ARCHIVELOG causes RMAN to
do the following:
1. Runs the ALTER SYSTEM ARCHIVE LOG CURRENT command.
2. Runs BACKUP ARCHIVELOG ALL. Note that if backup optimization is enabled, then
RMAN skips logs that it has already backed up to the specified device.
3. Backs up the rest of the files specified in BACKUP command.
4. Runs the ALTER SYSTEM ARCHIVE LOG CURRENT command.
5. Backs up any remaining archived logs generated during the backup.
This guarantees that datafile backups taken during the command are recoverable to a
consistent state.
Syntax:
BACKUP FULL Options
BACKUP FULL AS (COPY | BACKUPSET) Options
BACKUP INCREMENTAL LEVEL [=] integer Options
BACKUP INCREMENTAL LEVEL [=] integer AS (COPY |
BACKUPSET) Options
BACKUP AS (COPY | BACKUPSET) Options
BACKUP AS (COPY | BACKUPSET) (FULL | INCREMENTAL LEVEL
[=] integer) Options
Options:
[backupOperand [backupOperand]...]
backupSpec [backupSpec]...
[PLUS ARCHIVELOG
[backupSpecOperand [backupSpecOperand]...]];
backupOperand::=
{ FORMAT [=] 'format_string' [, 'format_string']...
| CHANNEL ['] channel_id [']
| CUMULATIVE
| MAXSETSIZE [=] integer [ K | M | G ]
| TAG [=] ['] tag_name [']
| keepOption
| SKIP { OFFLINE | READONLY | INACCESSIBLE }
| VALIDATE
| NOT BACKED UP [SINCE TIME [=] 'date_string']
| COPIES [=] integer
| DEVICE TYPE deviceSpecifier
.
.
.
}
backupSpec::=
[(]
{ BACKUPSET
{ {ALL | completedTimeSpec }
| primary_key) [, primary_key]...
}
| COPY OF { DATABASE
| TABLESPACE ['] tablespace_name ['] [,
['] tablespace_name
[']]...
| DATAFILE datafileSpec [, datafileSpec]...
}
| DATAFILE datafileSpec [, datafileSpec]...
| DATAFILECOPY 'filename' [, 'filename']...
| DATAFILECOPY FROM TAG [=] ['] tag_name ['] [,
['] tag_name [']]...
| DATAFILECOPY { ALL | LIKE 'string_pattern' }
| TABLESPACE ['] tablespace_name ['] [,
['] tablespace_name [']]...
| DATABASE
| archivelogRecordSpecifier
| CURRENT CONTROLFILE [FOR STANDBY]
| CONTROLFILECOPY 'filename'
| SPFILE
}
[backupSpecOperand [backupSpecOperand]...]
backupSpecOperand::=
{ FORMAT [=] 'format_string' [, 'format_string']...
| CHANNEL ['] channel_id [']
| CUMULATIVE
| MAXSETSIZE [=] integer [ K | M | G ]
| TAG [=] ['] tag_name [']
| keepOption
| SKIP { OFFLINE | READONLY | INACCESSIBLE }
| NOT BACKED UP [ SINCE TIME [=] 'date_string'
| integer TIMES
]
| DELETE [ALL] INPUT
.
.
.
}
.
Examples
Backup datafiles:
RMAN> BACKUP AS BACKUPSET DATAFILE
'ORACLE_HOME/oradata/trgt/users01.dbf',
'ORACLE_HOME/oradata/trgt/tools01.dbf';
Backup tablespace:
RMAN> BACKUP TABLESPACE system, users, tools;
Backup controlfile:
RMAN> BACKUP CURRENT CONTROLFILE TO '/backup/cntrlfile.copy';
Backup everything:
RMAN> BACKUP BACKUPSET ALL;
Backup Validation confirms that a backup could be run, by confirming that all database
files exist and are free of physical and logical corruption, this does not generate any
output.
Example:
"It's a very sobering feeling to be up in space and realize that one's safety factor was
determined by the lowest bidder on a government contract" - Alan Shepherd
General Backup and Recovery questions
[edit]Why and when should I backup my database?
Backup and recovery is one of the most important aspects of a DBA's job. If you lose your company's
data, you could very well lose your job. Hardware and software can always be replaced, but your data
may be irreplaceable!
Normally one would schedule a hierarchy of daily, weekly and monthly backups, however consult with
your users before deciding on a backup schedule. Backup frequency normally depends on the following
factors:
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.
Export/Import - Exports are "logical" database backups in that they extract logical definitions and
data from the database to a file. See theImport/ Export FAQ for more details.
Cold or Off-line Backups - shut the database down and backup up ALL data, log, and control
files.
Hot or On-line Backups - If the database is available and in ARCHIVELOG mode, set the
tablespaces into backup mode and backup their files. Also remember to backup the control files and
archived redo log 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.
Recovery is the process of applying redo logs to the database to roll it forward. One can roll-forward until
a specific point-in-time (before the disaster occurred), or roll-forward until the last transaction recorded in
the log files.
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/.
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.
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=...
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.
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 the following queries to get a list of all files that needs to be backed up:
Sometimes Oracle takes forever to shutdown with the "immediate" option. As workaround to this problem,
shutdown using these commands:
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.
[edit]My
database was terminated while in BACKUP MODE, do I need to
recover?
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.
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.
When in backup mode, Oracle will write complete changed blocks to the redo log files. Normally only
deltas (change vectors) are logged to the redo logs. This is done to enable reconstruction of a block if
only half of it was backed up (split blocks). Because of this, one should notice increased log activity and
archiving during on-line backups.
In fact RMAN, is just a Pro*C application that translates commands to a PL/SQL interface. The PL/SQL
calls are stallically linked into the Oracle kernel, and does not require the database to be opened (mapped
from the ?/rdbms/admin/recover.bsq file).
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:
Here is an 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.
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.
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.
The above Media Management Vendors will provide first line technical support (and installation guides)
for their respective products.
When allocating channels one can specify Media Management spesific parameters. Here are some
examples:
Netbackup on Solaris:
Netbackup on Windows:
or:
Lastly, write a RMAN script like this to do the cloning, and call it with "rman cmdfile dupdb.rcv":
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.
[edit]Can
one restore RMAN backups without a CONTROLFILE and
RECOVERY CATALOG?
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:
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;
'/flash_recovery_area/ORCL/backupset/2004_08_20/o1_mf_ncsnf_TAG20040820T153256
_0lczfrx8_.bkp';
v_pieceName(2) :=
'/flash_recovery_area/ORCL/backupset/2004_08_20/o1_mf_nnndf_TAG20040820T153256
_0lczd9tf_.bkp';
v_maxPieces := 2;
-- CFNAME mist be the exact path and filename of a controlfile taht was
backed-up
DBMS_BACKUP_RESTORE.restoreControlFileTo(cfname=>'/app/oracle/oradata/orcl/con
trol01.ctl');
SQL> ! ls -l /oradata/orcl/control01.ctl
-rw-r----- 1 oracle dba 3096576 Aug 20 16:45
/oradata/orcl/control01.ctl[/code]
Database altered.
Database altered.