A concise tutorial on Rman Five--rman restore and recovery

Source: Internet
Author: User
Tags dba tag name oracle database

I. General restore and recovery
The entire recovery process for RMAN can be divided into restoration (restore) and recovery (recover). They are very different in meaning, one refers to the physical meaning of the restoration and copy of the file, one refers to the recovery of database consistency, so the correct understanding of these two concepts, to facilitate the correct recovery of the database.
For Rman backups, the restore operation can only be done with an Rman or Rman package and is flexible for recovery operations, except for Rman, which can be done in sqlplus. Restoring and restoring a database can be done with the following two simple commands
Rman>restore database;
Rman>recover database;
Restoring a table space, or recovering a data file, may take less time to recover than to restore the database.
Rman> SQL "ALTER tablespace tools OFFLINE IMMEDIATE";
Rman> RESTORE tablespace tools;
Rman> RECOVER tablespace tools;
Rman> SQL "ALTER tablespace tools ONLINE";
For databases and data files, you can restore from the specified tag
Rman>restore datafile 1 from tag= ' TAG name '
For incomplete restores, such as Point-in-time restores, there may be only a full restore of the database.
Rman> RUN {
2> ALLOCATE CHANNEL C1 TYPE DISK;
3> ALLOCATE CHANNEL C2 TYPE DISK;
4> SET UNTIL time = ' 2002-12-09:11:44:00 ';
5> RESTORE DATABASE;
6> RECOVER DATABASE;
7> ALTER DATABASE OPEN resetlogs; }
Incomplete recovery can also be used with log-based recovery in RMAN
Rman> RUN {
2> SET UNTIL SEQUENCE) THREAD 1;
3> ALTER DATABASE MOUNT;
4> RESTORE DATABASE;
5> RECOVER DATABASE; # recovers through log 119
6> ALTER DATABASE OPEN resestlogs;
7>}
If possible, you can also restore the data files to a new location
SET NEWNAME for DataFile
'/u01/oradata/tools01.dbf ' to '/tmp/tools01.dbf ';
RESTORE datafile '/u01/oradata/tools01.dbf ';
SWITCH datafile All;
In addition to restoring the database and data files, we can also restore the control files, which need to be started under Nomount, with the following
The command can be 14
Restore controlfile from ' file name '
Restore Controlfile from Autobackup
Restore controlfile from tag= ' ... '
Under normal circumstances, the recovery process will automatically look for the required archive log without recovering the archive log, and we can also specify where to recover.
SET archivelog destination to '/u02/tmp_restore ';
RESTORE Archivelog All;
If the server parameter file (spfile) is used, Rman can back up the parameter file, and if a file corruption occurs, you can recover the SPFile parameter file with Rman and, in the absence of a parameter file, start the database with the Rman temporary parameter file to Nomount, Execute the following command
Restore Controlfile from Autobackup
Restore controlfile from ' file name '
Ii. Recovery under special circumstances
In the assumption that the recovery directory and the control file are lost, only backup sets and backup slices are left, and this time, it may only be recovered from the file. Here is an example of invoking the Dbms_backup_restore package to recover from a file.
Declare
Devtype varchar2 (100);
Done Boolean;
RECID number;
Stamp number;
FullName VARCHAR2 (80);
Begin
Devtype: =
Dbms_backup_restore.deviceallocate (' sbt_tape ',params=> ' env=
(Nsr_server=backup_server) ");
Dbms_backup_restore.restoresetdata file;
Dbms_backup_restore.restorecontrolfileto (
' First_control_file ');
Dbms_backup_restore.restorebackuppiece (' backup_piece ', done);
Dbms_backup_restore.copycontrolfile (' First_control_file ',
' Second_control_file ', RecId, stamp,fullname);
--Repeat the above copycontrolfile for all control file
End /
third, restore inspection and recovery test
As with a backup check, the restore operation can also check whether restore is normal or if the backup set is valid. Such as:
rman> RESTORE DATABASE VALIDATE;
rman> VALIDATE backupset 218;
Recover can also test, detect recovery errors, error information recorded in the alert file, through the test, we can know whether the recovery operation can be completed properly. 15
Sql>recover tablespace sales TEST;
Sql>recover DATABASE UNTIL CANCEL TEST
Four, block-level recovery
Block recovery blocks Media Recovery (BMR), block is the smallest unit of recovery, through blocks can reduce recovery time, and data files can be online. When restoring a block, you must specify a specific block number, such as:
Blockrecover datafile 6 block 3;
Bad block information to be recovered can be obtained from alert and trace files, table and index analysis, DBV tools or third-party Media management tools, and specific query statements. The cause of block corruption is generally a discontinuous or random IO error or a block error in memory.
Block error messages are saved in v$database_block_corruption, and the bad blocks listed in the view are restored with the following command
rman> blockrecover Corruption LIST
2> RESTORE UNTIL time ' sysdate–10 ';
Bad block information for backup is saved in
V$backup_corruption
V$copy_corruption
You can use the following command to recover a bad block.
Blockrecover datafile 2 block, datafile 7 blocks 5, datafile 9 block 19;
Blockrecover tablespace SYSTEM DBA 4194404, 4194405 from TAG
"Weekly_backup";
Blockrecover tablespace SYSTEM DBA 4194404, 4194405 RESTORE UNTIL time
' SYSDATE-2 ';
v. Database replication
Rman can be used to replicate and clone databases, and Rman provides a specific command to do this. Such as
CONNECT TARGET
CONNECT Auxiliary sys/aux_pwd@newdb
DUPLICATE TARGET DATABASE to NDBNEWH
LOGFILE
'?/dbs/log_1.f ' SIZE 100M,
'?/dbs/log_2.f ' SIZE 100M
SKIP READONLY
Nofilenamecheck;
Before the above command is executed, note the following points
1. Back up all the data files on the main library, control the files, and the archived logs that are generated after the backup, and copy the backup to the same directory as the machine that needs to be replicated (if not the same directory, consider setting up a link in the Linux/unix environment).
2, copy the main database initialization parameter files to the copied machine, and make the appropriate changes, such as modify the database name and instance name

3, create a new password file on the machine to be replicated, and start the replicated database under Nomount.
4, configure the primary database to the replication database network connection or copy the database to the primary database connection.
5, in the main database or replicated database to run Rman, respectively, connect the main database and copy database instance.
6, run the copy command, the command will restore all the data files, recreate the control file, and use the new parameter file to start the recovery database to a consistent state, and finally open the database in Resetlog mode, create the specified redolog.
The copy command can also replicate from a backup on tape, change the database name, change the new path to the database file, and revert to a previous point in time, skipping tablespaces that do not need to be replicated, such as a more complex replication command:
RUN
{
ALLOCATE Auxiliary CHANNEL newdb1 DEVICE TYPE SBT;
DUPLICATE TARGET DATABASE to newdb
db_file_name_convert= ('/h1/oracle/dbs/trgt/', '/h2/oracle/oradata/newdb/')
UNTIL time ' SYSDATE-1 ' # Specifies incomplete recovery
Skip Tablespace Cmwlite, Drsys, example # Skip desired tablespaces
PFILE =?/dbs/initnewdb.ora
LOGFILE
GROUP 1 ('/oradata/newdb/redo01_1.f ',
'?/oradata/newdb/redo01_2.f ') SIZE 200K,
GROUP 2 ('/oradata/newdb/redo02_1.f ',
'?/oradata/newdb/redo02_2.f ') SIZE 200K
GROUP 3 ('/oradata/newdb/redo03_1.f ',
'?/oradata/newdb/redo03_2.f ') SIZE 200K reuse;
}
Vi. use of Rman to create an alternate database
There are two ways to create an alternate database using RMAN, one of which is a regular Restore command that uses standby control files from the primary database to boot the standby to the standby mount, at which point the standby database has no data files. Then on the standby, start the Rman command, connect the database (like the primary database dbid), and restore the Rman backup copied from the primary database. Finally, as with other methods, enter the standby management recovery model.
Another option is to copy the commands, such as
DUPLICATE TARGET DATABASE for STANDBY Nofilenamecheck;
This process is described in detail below.
1, create alternate parameter file and password file, start the standby database to Nomount
2, back up the main database and standby control files and all archiving
Rman> Backup Database;
Rman> Backup current controlfile for standby;
Rman> sql "Alter System Archive Log current";
Rman> Backup filesperset archivelog all delete input;
3, copy all the backup to the standby database under the same path
4, configure the primary database to the standby database connection
5. Start Rman
Rman Target/auxiliary Sys/change_on_install@standby 17
6, start creating an alternate database
Rman> duplicate target database for standby dorecover Nofilenamecheck;
The whole process includes the creation of the standby control file, boot to Mount, the path transformation specified in the parameter file, the restoration of the data file, the restoration of the archive log, and so on.
7, the final recovery log and boot to the administrative recovery mode.
sql> Recover standby database;
sql> ALTER DATABASE recover managed standby database disconnect;

Oracle Community PDM Chinese Network: Http://www.pdmcn.com/bbs,

Oracle expert QQ Group: 60632593, 60618621

Oracle Technical Data: Oracle 9i Rman Reference Manual, oracle10g backup and restore,Oracle Database 10gRMAN Backup and Recovery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.