RMAN concise tutorial 5-Restore and restore RMAN

Source: Internet
Author: User

I. Conventional restoration and recovery
The entire recovery process of RMAN can be divided into a restore and a recover. They have a very different meaning. One is the restoration and copying of physical files, one is the restoration of Database Consistency. Therefore, a correct understanding of these two concepts will help you recover the database correctly.
For RMAN backup, The Restoration Operation can only be performed using the RMAN or RMAN package. The Restoration Operation is flexible. Besides rman, it can also be completed in sqlplus. You can use the following two simple commands to restore and restore a database:
RMAN> Restore database;
RMAN> recover database;
It may take less time to restore a tablespace or a data file.
RMAN> SQL "alter tablespace tools offline immediate ";
RMAN> restore tablespace tools;
RMAN> recover tablespace tools;
RMAN> SQL "alter tablespace tools online ";
Databases and data files can be recovered from the specified tag.
RMAN> restore datafile 1 from tag = 'tagname'
For Incomplete recovery such as restoration at a time point, the database may only be completely restored.
RMAN> run {
2> allocate channel C1 type disk;
3> allocate channel C2 type disk;
4> set until time = '2017-12-09: 11: 44: 00 ';
5> Restore database;
6> recover database;
7> alter database open resetlogs ;}
Incomplete recovery in rman, log-based recovery can also be used.
RMAN> run {
2> set until sequence 120 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 restore the data file 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 file, which needs to be started under nomount, using the following
To 14
Restore controlfile from 'file name'
Restore controlfile from autobackup
Restore controlfile from tag = '...... '
Under normal circumstances, you do not need to restore the archived logs. The recovery process will automatically search for the required archived logs. Of course, you can also specify the recovery location.
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. If the file is damaged, RMAN can be used to restore the spfile parameter file. If no parameter file exists, use the temporary RMAN parameter file to start the database to nomount and execute the following command:
Restore controlfile from autobackup
Restore controlfile from 'file name'
Ii. Recovery in special circumstances
Assume that the recovery directory and control file are lost, and only the backup set and backup slices are left. At this time, only the files can be recovered. The following example shows how to restore data from a file by calling the dbms_backup_restore package.
Declare
Devtype varchar2 (100 );
Done Boolean;
Recid number;
Stamp number;
Fullname varchar2 (80 );
Begin
Devtype: =
Dbms_backup_restore.deviceallocate ('sbt _ tape ', Params => 'env =
(Ns_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 each control file
End ;/
Iii. Restoration check and restoration test
Like the backup check, the restore operation can also check whether the restore is normal or whether the backup set is valid. For example:
RMAN> Restore database validate;
RMAN> validate backupset 218;
Recover can also be tested to detect recovery errors. The error information is recorded in the alert file. Through the test, we can know whether the recovery operation can be completed normally. 15
SQL> recover tablespace sales test;
SQL> recover database until cancel Test
Iv. Block-level recovery
Block recovery block media recovery (BMR). A block is the minimum unit for restoration. The block can reduce the recovery time and the data files can be online. When you restore a block, you must specify a specific block number, such:
Blockrecover datafile 6 block 3;
The information about the bad blocks to be restored can be obtained from the alarm and tracking files, table and index analysis, DBV tools, third-party media management tools, and specific query statements. Block damage is generally caused by intermittent or random Io errors or memory block errors.
Block Error information is saved in V $ database_block_partition uption. Run the following command to restore the Bad blocks listed in this view:
RMAN> blockrecover upload uption list
2> restore until time 'sysdate-10 ';
Bad block information of backup is stored in
V $ backup_upload uption
V $ copy_uption
You can use the following command to restore the damaged block.
Blockrecover datafile 2 Block 12, 13 datafile 7 block 5, 98, 99 datafile 9 block 19;
Blockrecover tablespace system DBA 4194404,419 4405 from tag
"Weekly_backup ";
Blockrecover tablespace system DBA 4194404,419 4405 restore until time
'Sysdate-2 ';
V. Database Replication
RMAN can be used for database replication and cloning. RMAN provides a dedicated Command to complete this operation. For example
Connect target
Connect Auxiliary Sys/aux_pwd @ newdb
Duplicate target database to ndbnewh
Logfile
'? /Dbs/log_1.f' size 100 m,
'? /Dbs/log_2.f 'size 100 m
Skip readonly
Nofilenamecheck;
Note the following points before executing the preceding commands:
1. Back up all data files, control files, and archive logs generated during and after backup in the master database, and copy the backup to the same directory of the machine to be copied (if not, you can create a link in Linux/Unix ).
2. Copy the initialization parameter file of the primary database to the copied machine and modify it accordingly, such as modifying the Database Name and Instance name.

3. Create a new password file on the machine to be copied and start the copied database to nomount.
4. Configure the network connection from the primary database to the replication database or the connection from the replication database to the primary database.
5. Run rman on the master database or the copied database to connect the master database and the copied database instance respectively.
6. Run the Copy command to restore all data files, recreate the control file, start and restore the database to a consistent State using the new parameter file, and open the database using resetlog, create the specified redolog.
The Copy command can also be used to copy the backup on the tape, change the database name, or change the new path of the database file and restore it to the previous time point, skip tablespaces that do not need to be copied, such as a complicated Copy 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 200 K,
Group 2 ('? /Oradata/newdb/redo02_1.f ',
'? /Oradata/newdb/redo02_2.f ') size 200 K
Group 3 ('? /Oradata/newdb/redo03_1.f ',
'? /Oradata/newdb/redo03_2.f ') size 200 K reuse;
}
6. Create a backup database using RMAN
Two methods can be used to create a backup database using RMAN. One is the conventional restore command. The standby control file copied from the primary database is used to start the backup database to the backup mount, at this time, the Standby database does not have data files. On the slave end, start the RMAN command to connect to the database (same as the master database dbid) and restore the RMAN backup copied from the master database. At last, it is the same as other methods and enters the Backup management and recovery mode.
Another method is to copy the command, as shown in figure
Duplicate target database for standby nofilenamecheck;
This process is described in detail below.
1. Create a backup parameter file and password file and start the backup database under nomount.
2. Back up master database and backup control files and all archives
RMAN> backup database;
RMAN> Backup current controlfile for standby;
RMAN> SQL "alter system archive log current ";
RMAN> Backup filesperset 10 archivelog all Delete input;
3. Copy all the backups to the same path of the backup database.
4. Configure the connection from the primary database to the standby Database
5. Start RMAN
RMAN target/auxiliary Sys/change_on_install @ standby 17
6. Start to create a backup database.
RMAN> duplicate target database for standby dorecover nofilenamecheck;
The entire process includes creating backup control files, starting to mount, path conversion, data file restoration, and archiving log restoration specified in parameter files.
7. Finally, recover the log and start it to the management recovery mode.
SQL> recover standby database;
SQL> alter database recover managed standby database disconnect;

 OracleCommunityPDM Chinese network:Http://www.pdmcn.com/bbs,

Oracle expert QQ group: 60632593 and 60618621

OracleTechnical materials: Oracle 9i RMAN reference user manual, Oracle10g backup and recovery,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.