Oracle RMAN
Oracle RMAN
ORA -- as oracle
$ ping bigdog.psoug.org
$ ping bigdog
$ ping 192.168.1.119
cd /network/admin
vi tnsnames.ora
-- save change
<Esc> zz
$ tnsping repos Put the Database into Archive Log Mode -- as oracle
$ sqlplus /nolog
RMAN> report need backup; Explore the RMAN Catalog SQL> SELECT
object_type, COUNT(*)
FROM user_objects
GROUP BY object_type;
RMAN> RUN
{
ALLOCATE CHANNEL d1 DEVICE TYPE DISK FORMAT
'/home/oracle/backup1/%U';
ALLOCATE CHANNEL d2 DEVICE TYPE DISK FORMAT
'/home/oracle/backup2/%U';
# AS COPY is default when backing up to disk
BACKUP DATABASE PLUS ARCHIVELOG;
}
SQL> desc v
-- need to look at data dictionary too Trash Control File and Recover $
cd /app/oracle/product/OracleHomes/oradata/orcl
$ ls -la
$ rm control02.ctl
$ cd /app/oracle/product/OracleHomes/admin/orcl/bdump
$ tail alert_orcl.log Trash Log File and Recover Error when you try to
start db after copying one logfile to another (a common mistake)
-- to recover
alter database clear unarchived logfile group 1;
alter database drop logfile group 1;
RMAN> run {
2> allocate channel c1 type disk;
3> backup database format '/nfs/curly/rman/o1/%u';
4> release channel c1;
5> }
RMAN> RMAN Demo 1 Target Database Not Running in Archive Log Mode
CONFIGURATION
There are various parameters that can be used to configure RMAN operations to suit your needs. Some of the things
that you can configure are:
- the required number of backups of each datafile
- the number of server processes that will do backup/restore operations
in parallel
- the directory where on-disk backups will be stored
It should be noted that configuration settings are stored persistently, and will be used by RMAN for all subsequent
backup, restore, recovery, and maintenance operations. Configure backups to be written
to disk.
NOTES:
If you want backups to go to tape, refer to the configuration
section in case2.rcv on how to configure tape backups. However in
case of disaster recover if RMAN is not connected to recovery
catalog, you will have to manually allocate all channels where
backups were taken.
The following scenario assumes that you want to take one full
database backup every week, and one incremental database backup
every day. The backup cycle starts on Friday. A full backup is
taken on Friday, and an incremental backup is taken every other
day. The retention policy of REDUNDANCY 5 applies only to full
(not incremental) backups, so the combination of that policy and
this backup schedule ensures that you can restore to any
incremental backup time for the last 5 weeks.
If the above backup fails for any reaon, you can use the NOT
BACKED UP SINCE
option on the BACKUP command (9i restartable backup feature) to
continue from the point of failure. The small value of
FILESPERSET is good for restartable backups. However you should
note that smaller FILESPERSET produces more backup sets.
The steps are the same as in section 2.1, except that the options
LEVEL 1 CUMULATIVE indicate that only the blocks that have
changed since the last level 0 backup will be backed up. If the
CUMULATIVE option was not specified, then only the blocks that
have changed since the last level 1 backup will be backed up. The
advantage of a cumulative backup is that only one incremental
backup ever needs to be applied during recovery.
It is assumed that you have all the configuration files like the
server
parameter file (spfile - equivalent of init.ora in 9i),
tnsnames.ora, and listener.ora in the appropriate places, and
that you can startup the Oracle instance in nomount mode and
connect from RMAN to the target instance.
The examples provided in this case study will use a disk area
(/backup directory) to hold the most recent one week of backups,
in order to expedite backup/restore operations. The size of this
area may vary depending on database size, redo generated, etc. If
you want all backups to go to tape, remove DEVICE TYPE DISK
option from the BACKUP commands given in this case study.
Only the incremental backups are stored on disk for one week. The
level 0 backup goes immediately to tape. This means that RMAN
will always have to read tape for recovery.
NOTES
You should not run all of the commands in this file in a single
RMAN
session. Rather, the various sections in this file should be
separated into individual RMAN scripts which can be run to
configure, backup, restore, and recover the database.
Organization:
CONFIGURATION
You can also follow the procedure given in case1.rcv for taking
consistent backups. Only disadvantage of taking consistent
backups is that you have to close database cleanly, and open in
restricted mode. Hence database is not available for general use
during consistent backup.
If the above backup fails for any reaon, you can use the NOT
BACKED UP SINCE option on the BACKUP command (9i restartable
backup feature) to continue from the point of failure. The small
value of FILESPERSET is good for restartable backups. However you
should note that smaller FILESPERSET produces more backup sets.
As in section 2.1, you can use the NOT BACKED UP SINCE option
with the BACKUP command (9i re-startable backup feature) to
continue from the point of failure.
Verify that all backups which RMAN thinks are stored by the
third-party media manager still exist, and generate a report of
backups that need to be taken to satisfy the retention policy.
CROSSCHECK BACKUP;
REPORT NEED BACKUP;
The RMAN report and list commands aren't very user-friendly if you are looking for something
specific. For example, if you want a list of the most recent Level 0 backups in a database, you
can devise a more specific query if you go into the database and use the v view:
RUN
{
SQL 'ALTER DATABASE DATAFILE 5 OFFLINE';
RESTORE DATAFILE 5;
RECOVER DATAFILE 5;
SQL 'ALTER DATABASE DATAFILE 5 ONLINE';
}
RUN
{
SQL 'ALTER TABLESPACE TBS_5 OFFLINE';
Start RMAN without the TARGET option, and use the following
commands to restore and recover the database:
# You must take a new whole database backup after resetlogs (as
# in Section 2.1), since backups of previous incarnation are not
easily
# usable.
}
# Section 5.4 - Block recovery
# Block recovery can be used to recover a corrupted block(s). It
is not
# intended to recover complete datafile.
# Usually, the corruption is reported in alert logs, trace files
or
# results of SQL commands
#
# For example, as a result of SQL command
# SQL> select * from emp;
#
#NAME
# You must take a new whole database backup after resetlogs (as
# in Section 2.1), since backups of previous incarnation are not
easily
# usable.
}
# You must take a new whole database backup after resetlogs (as
# in Section 2.1), since backups of previous incarnation are not
easily
# usable.
} RMAN Demo 3 # DESCRIPTION
# This case study outlines the basic steps to perform tablespace
# point-in-time recovery (TSPITR) using Recovery Manager.
#
# The examples in this case study assume that all backups are stored on
# disk. However if you have backups on tape and channels are configured as
# described in case2.rcv, Section 1, the same procedures will work.
#
# This case study assumes that
# - You want to recover tablespaces TBS1 and TBS2 to the point in time
# '2000-APR-01:07:05:30'.
# - TSPITR is performed on the same machine as the target database.
# - ORACLE_HOME is /oracle.
# - ORACLE_SID for the target database is PROD.
# - target database files and online logs are in /dbs/.
# - ORACLE_SID for the auxiliary instance is AUX.
# - all temporary files (except password file) for the auxiliary
# instance are created in /auxiliary.
#
# NOTES
# You should not run all of the commands in this file in a single RMAN
# session. Rather, the various sections in this file should be studied
# thoroughly before performing TSPITR.
#
# MODIFIED (MM/DD/YY)
# banand 04/17/01 - re-write case for tablespace point-in-time recovery
# banand 04/17/01 - Creation
#
# Organization:
#
# This case study is organized into the following sections:
# 1. TSPITR usage and restrictions
# 2. Resolving referential dependencies
# 3. Preparing for TSPITR - setup auxiliary instance
# 4. Performing TSPITR
# 5. Preparing the target database to use recovered files
# 6. Cleaning up the auxiliary instance and temporary files
#
After TSPITR you should take a new backup of the recovered tablespace(s),
since it is not possible to recover using the pre-TSPITR backups.
Oracle provides the TS_PITR_CHECK view to assert that no referential integrity constraints will be
broken after TSPITR. If this view returns rows when queried then the reason should be investigated and
resolved. Only when TS_PITR_VIEW returns no rows TSPITR will be able to proceed (since this view is
checked by imp/exp utilities called by RMAN during
TSPITR). All actions taken at this stage should be noted in order that these relationship can be rebuilt
after TSPITR is complete.
You should check view TS_PITR_OBJECTS_TO_BE_DROPPED to see which objects will be lost after
TSPITR. If you want certain object listed by this view, then TSPITR should not be performed.
Run the following queries to prepare for performing TSPITR on TBS1 and TBS2 to time '2000-APR-
01:07:05:30':
This section shows how to set up the auxiliary instance which will be used by RMAN to perform TSPITR
on the desired tablespaces. RMAN will connect to this database using the AUXILIARY connect option.
Section 3.1.1 - Preparing to connect to the auxiliary instance The following steps should be followed to
connect to the auxiliary instance:
- create a password file for the auxiliary instance using the orapwd utility:
orapwd file=/oracle/dbs/orapwAUX password=auxpwd entries=100
Add listener.ora and tnsnames.ora entries so that RMAN can connect to the auxiliary database.
Section 3.1.2 - Preparing the parameter file for the auxiliary instance You can use the production instance parameter
file as the basis for the auxiliary instance. However certain parameters like db_block_buffers, shared_pool_size,
large_pool_size, enqueue_resources, etc which allocate shared memory can probably be reduced, because the
auxiliary instance does not have the same memory requirements as the production instance.
The following parameters must be set for the auxiliary instance: db_name must be the same as in the production
instance
db_name=PROD
db_file_name_convert and log_file_name_convert are used only in the parameter file of the auxiliary
instance. They establish the rules that are used to convert the datafile and log file names from the
production to the auxiliary database.
Note that starting in Oracle9i, more than one pair of substitutions can be specified in both of these
parameters, which allows more flexibility in converting file names. Use the RMAN SET NEWNAME
command to convert any file names that cannot be converted with the xxx_file_name_convert
parameters.
db_file_name_convert=('/dbs/', '/auxiliary/')
log_file_name_convert=('/dbs/', '/auxiliary/')
It is important to note that ALL controlfiles, online logs, and datafiles must have different names at the
auxiliary instance than they have at the production instance, otherwise RMAN may restore files to those
locations, and overwrite the production files. Use the control_files, db_file_name_convert, and
log_file_name_convert parameters to make sure
that the files at the auxiliary instance all have different names.
The auxiliary database must be in nomount state and the target instance must be mounted or open state
to perform TSPITR. The steps in RMAN TSPITR
are:
- connect to auxiliary instance
- connect to target database
- connect to recovery catalog (optional)
- recover tablespace TBS1 and TBS2
RUN
{
# optionally, use SET NEWNAME here for file name translation
# SET NEWNAME FOR DATAFILE 1 TO '/oracle/auxiliary/file1.f'
# SET NEWNAME FOR DATAFILE 2 TO '/oracle/auxiliary/file2.f'
All the recovered tablespaces will be OFFLINE in target database on successful execution of RECOVER
command. If the RECOVER command fails, then after resolving the error you can re-execute the
commands.
If export fails due to lack of temporary space, you can create a temporary tablespace. Search for tspitr_7
in /oracle/rdbms/admin/recover.bsq and see comments to create temporary tablespace.
If import fails because of import tables not existing, you can run CATEXP.SQL on target database to
create import schema. Preparing the target database to use the recovered tablespaces
After the RECOVER command in Section 4 runs successfully, you should backup the recovered
tablespaces, because after they are brought online, they can no longer be recovered using backups taken
prior to the TSPITR.
The auxiliary instance is not usable after successful completion of TSPITR. This instance must be
cleaned using following steps:
- Connect to the auxiliary instance as explained in Section 3.1.3
- mount the database using 'ALTER DATABASE MOUNT CLONE DATABASE'
- Delete the temporary files restored by RMAN when performing TSPITR.
SELECT d.name
FROM gv d, gv t
WHERE d.ts#=t.ts# AND status in ('SYSTEM', 'ONLINE')
AND t.name not in ('TBS1', 'TBS2');
- Shutdown the auxiliary instance and delete the above files. All these files in this case should be in the
/oracle/auxiliary directory.
RUN
{
# STARTUP MOUNT;
# By default the DUPLICATE command will try to create the
duplicate database
# using the most recent backup of the target database. If you
wish to
# recover the duplicate database to a non-current time issue a
SET UNTIL
# command to speceify the time.
# LOGFILE
# GROUP 1 ('?/dbs/new_g1_l1.dbf',
# '?/dbs/new_g1_l2.dbf') SIZE 512K,
# GROUP 2 ('?/dbs/new_g2_l1.dbf',
# '?/dbs/new_g2_l2.dbf') SIZE 512K
# NOFILENAMECHECK
# Note that read-only datafiles are duplicated by default. If
this is not
# desired, use the SKIP READONLY clause:
# SKIP READONLY