ITPub博客

RMAN Restore

原创 Linux操作系统 作者:duyiwei 时间:2007-11-21 00:00:00 0 删除 编辑

Purpose

To restore files from backups or image copies. By default, RMAN restores files to their default location. You can use the SET NEWNAME command to restore files to nondefault locations. RMAN restores backups from disk or tape and restores images copies from disk only.


Typically, you restore when a media failure has damaged a current datafile, control file, or archived log or prior to performing a point-in-time recovery. The RESTORE command restores full backups, incremental backups (level 0 only), or copies of datafiles, control files, and archived redo logs. Because the RECOVER command automatically restores archived logs as needed, you should seldom need to restore logs manually. Possible reasons for manually restoring archived logs are to speed up recovery or to stage the logs to multiple destinations.


Note:

In Oracle9i, unlike in previous RMAN releases, RMAN by default does not restore a datafile if the file is in the correct place and its header contains the expected data (RMAN does not scan the datafile body for corrupt blocks). The FORCE option overrides this behavior and restores the requested files unconditionally.


When you run RESTORE in CATALOG mode with a backup control file, RMAN automatically adjusts the control file to reflect the structure of the restored database.

If you restore to the default location, then RMAN overwrites files with the same filenames. If you restore to a new location, then issue SET NEWNAME commands to rename the files and issue a SWITCH command to make the restored files current. If you do not issue SWITCH commands, then RMAN considers the restored files as valid copies for use in future restore operations.

If you do not manually allocate channels, then RMAN allocates all automatic channels possibly needed by the RESTORE command. For example, assume you configure 3 separate sbtchannels (each with different PARMS) and then configure parallelism for DISK and sbt as follows:

CONFIGURE DEVICE TYPE DISK PARALLELISM 2;
CONFIGURE DEVICE TYPE sbt PARALLELISM 3;
CONFIGURE DEFAULT DEVICE TYPE TO sbt;

During a restore, RMAN allocates three sbt channels and the two preconfigured DISK channels. For a restore, RMAN allocates all configured channels unless the DEVICE TYPE option restricts the device type from which RMAN restores files.

In a Real Application Clusters configuration, RMAN automatically restores backups, control file copies, and datafile copies from channels that can read the files on tape or a local file system. For example, if channel 1 connected to instance 1 can read log 1000 from its tape drive, but channel 2 connected to instance 2 cannot read the log from its tape drive, then channel 1 restores the log. Autolocation is automatically enabled when the channels meet any of the following criteria:

Restrictions and Usage Notes

  • To restore datafiles to their current location, the database must be started, mounted, or open with the tablespaces or datafiles to be restored offline. If the database is started but not mounted, then it is recommended that you only restore the control file, if necessary (refer to "Restrictions and Usage Notes for RESTORE CONTROLFILE"). To restore other files, mount the database and then continue.


    Note:

    When performing a database validation by using RESTORE ... VALIDATE, the database can be open.


  • To restore to a new location, run SET NEWNAME commands to rename the datafiles and SWITCH commands to make them the current database files. If you do not use SWITCH, then the repository lists restored datafiles as datafile copies.
  • If you use the FROM DATAFILECOPY option, then the allocated channels must be of DEVICE TYPE DISK.
  • If you use the FROM BACKUPSET operand, then the appropriate type of storage devices must be allocated for the backup sets that need to be restored. If the appropriate device is not allocated, then you may not be able to find a candidate backup set or copy to restore, and the RESTORE command fails.
  • RMAN only restores backups that were created on the same type of channels that are allocated for the RESTORE command.

    For example, if you made some backups of a datafile to DISK channels and others to sbt channels, and only a DISK channel is allocated for the RESTORE command, RMAN will not restore backups that were created on sbt channels.

  • If datafile names are symbolic links, that is, files pointing to other files, then the control file stores the filenames of the link files but RMAN performs I/O on the datafiles pointed to by the link files. If a link file is lost and you RESTORE a datafile without re-creating the symbolic link, then RMAN restores the datafile to the location of the link file rather than to the location pointed to by the link.
  • You can only restore from a previous incarnation when restoring the whole database. For example, you cannot restore one datafile of a previous incarnation while the current database is in a different incarnation.
  • If the database is started but not mounted in NOCATALOG mode, then the RESTORE SPFILE command requires the FROM AUTOBACKUP clause.
  • If you are restoring the server parameter file and the control file in a disaster recovery situation, you cannot run RESTORE CONTROLFILE FROM AUTOBACKUP, mount this control file, and then run RESTORE SPFILE without the FROM AUTOBACKUP clause.
  • Do not specify a datafile more than once in a restore job. For example, the following command is illegal because datafile 1 is both specified explicitly and implied by the SYSTEMtablespace:
    RESTORE TABLESPACE SYSTEM DATAFILE 1;
    
    
  • You must have already configured a device type by using CONFIGURE (except for DISK, which is preconfigured) before specifying the DEVICE TYPE option.
  • You cannot manually allocate channels and then run RECOVER DEVICE TYPE.
  • RMAN neither backs up nor restores locally-managed temporary tablespaces, although it can back up and restore dictionary-managed temporary tablespaces.

Restrictions and Usage Notes for RESTORE CONTROLFILE

  • After you restore a backup control file, you must run RECOVER DATABASE and then open the database with the RESETLOGS option.
  • After restoring a backup control file, entries for tempfiles in locally-managed temporary tablespaces are removed. Hence, you must add new tempfiles to these tablespaces after you open with the RESETLOGS option. If you do not, then Oracle can display the following error for when attempting to sort: ORA-25153: Temporary Tablespace is Empty.
  • If you restore a control file from a release earlier than release 8.1.6 on Windows NT that has not been normalized, then you must normalize it before mounting the database by following the procedure described in Oracle9i Database Migration. A flawed mechanism in releases prior to release 8.1.6 on Windows NT could allow two different filenames to refer to the same physical file.

Table 2-25 indicates the restrictions that apply in different situations involving the RESTORE CONTROLFILE command.

Table 2-25 RESTORE CONTROLFILE Scenarios
RESTORE CONTROLFILE;RESTORE CONTROLFILE FROM AUTOBACKUP;RESTORE CONTROLFILE ... TO 'filename';RESTORE CONTROLFILE ... FROM 'media_handle' or TAG;

No catalog, target started

Error. Must specify FROMAUTOBACKUP.

First run SET DBID. Restores toCONTROL_FILES locations.

First run SET DBID. Must specifyFROM AUTOBACKUP. Restores only to filename.

First run SET DBID. Restores from specified file (cannot restore from TAG). If TO 'filename' not used, restores to allCONTROL_FILES locations.

No catalog, target mounted or open

Error. Must use TO 'filename', where filename is not inCONTROL_FILES list.

Error. Must use TO 'filename', where filename is not inCONTROL_FILES list.

Restores only to filename, wherefilename is not inCONTROL_FILES list.

Restores from specified file. If TO 'filename' not used, restores to all CONTROL_FILES locations.

Catalog, target started

Restores to CONTROL_FILESlocations. Run SET DBID only if
DB_NAME not unique in catalog.

Do not use with catalog unless for testing purposes.

Restores only to filename, wherefilename is not inCONTROL_FILES list.

Restores from specified file. If TO 'filename' not used, restores to all CONTROL_FILES locations.

Catalog, target mounted or open

Error. Must use TO 'filename', where filename is not inCONTROL_FILES list.

Do not use with catalog.

Restores only to filename, wherefilename is not inCONTROL_FILES list.

Restores from specified file. If TO 'filename' not used, restores to all CONTROL_FILES locations.

Examples

Restoring a Tablespace: Example

This example takes a tablespace offline, restores it, then performs media recovery:

SQL "ALTER TABLESPACE users OFFLINE IMMEDIATE"; 
RESTORE TABLESPACE users; 
RECOVER TABLESPACE users;  
SQL "ALTER TABLESPACE users ONLINE";
Restoring the Control File When Using a Recovery Catalog: Example

This example restores the control file to its default location, replicates it automatically to all CONTROL_FILES locations, and mounts the database:

RUN
{ # SET DBID is not necessary when connected to a recovery catalog
  STARTUP FORCE NOMOUNT;
  RESTORE CONTROLFILE;
  ALTER DATABASE MOUNT;
}
Restoring the Control File with a Tag: Example

This NOCATALOG example restores the control file specified by a tag, and then mounts the database:

CONNECT TARGET /
STARTUP NOMOUNT;
SET DBID 320066378;  # required when restoring control file in NOCATALOG mode
RESTORE CONTROLFILE FROM TAG 'monday_cf_backup';
ALTER DATABASE MOUNT;
Restoring the Database with a Backup Control File: Example

This example restores the control file, replicates it to all control file locations specified in the parameter file, and then restores and recovers the database:

CONNECT TARGET /
STARTUP NOMOUNT;
SET DBID 320066378;  # required when restoring control file in NOCATALOG mode
RUN
{
  ALLOCATE CHANNEL c1 DEVICE TYPE sbt;
  RESTORE CONTROLFILE TO '/tmp/control01.ctl' FROM AUTOBACKUP;
  RESTORE CONTROLFILE FROM '/tmp/control01.ctl'; # restores to all CONTROL_FILES locations
  ALTER DATABASE MOUNT;
  RESTORE DATABASE;
  RECOVER DATABASE;
}
ALTER DATABASE OPEN RESETLOGS;
# if the database uses locally-managed temporary tablespaces, then add new tempfiles
# to these tablespaces after the RESETLOGS
SQL "ALTER TABLESPACE temp ADD TEMPFILE ''?/oradata/trgt/temp01.dbf'' REUSE";
Restoring Archived Redo Logs to a New Location: Example

This example restores all archived redo logs to the /oracle/temp_restore directory:

RUN
{ 
  SET ARCHIVELOG DESTINATION TO '/tmp';
  RESTORE ARCHIVELOG ALL;
}
Restoring a Control File Autobackup to a Nondefault Location: Example

This example restores the latest control file autobackup made on or before June 23, 2000 with a nondefault format of PROD_CF_AUTOBACKUP_%F. It starts searching for backups with a sequence number of 20, and searches backward for 5 months:

SET DBID 320066378;  # required when restoring control file in NOCATALOG mode
RUN
{
  SET UNTIL TIME '23-JUN-2001 00:00:00';
  SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE sbt TO 'prod_cf_autobackup_%F';
  ALLOCATE CHANNEL CHANNEL_1 DEVICE TYPE sbt;
  RESTORE CONTROLFILE TO '/tmp/autobackup_20001002.dbf' FROM AUTOBACKUP 
    MAXSEQ 20 MAXDAYS 150;
}
Restoring the Server Parameter File to Current Location: Example

The following shell script restores the current server parameter file in NOCATALOG mode:

#!/usr/bin/tcsh
rman TARGET / <SET DBID 1447326980 # set dbid to dbid of target database
STARTUP FORCE NOMOUNT; # start instance with dummy SPFILE
RUN
{
  ALLOCATE CHANNEL c1 DEVICE TYPE sbt;
  RESTORE SPFILE FROM AUTOBACKUP; # FROM AUTOBACKUP needed in NOCATALOG mode
}
STARTUP FORCE; # start with restored SPFILE and open database
EXIT
EOF
Restoring the Server Parameter File to a Nondefault Location: Example

The following shell script restores a server parameter file that was backed up at least a month ago and restarts the database with the restored parameter file:

#!/usr/bin/tcsh
echo "SPFILE=/tmp/spfileTEMP.ora" > /tmp/initTEMP.ora
rman TARGET / <STARTUP FORCE MOUNT; # make sure database is mounted so SET DBID not required
RESTORE SPFILE TO '/tmp/spfileTEMP.ora' UNTIL 'SYSDATE-31';
STARTUP FORCE PFILE=/tmp/initTEMP.ora; # start with restored SPFILE and open database
EXIT
EOF

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/54666/viewspace-17010/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2007-12-10

  • 博文量
    28
  • 访问量
    95748