V. Restoration and recovery

Source: Internet
Author: User

V. Restoration and recovery
5.1 conventional restoration and recovery
The entire recovery process of RMAN can be divided into restoration and recovery.
The difference is that one refers to the restoration and copying of physical files, and the other refers to the restoration of Database Consistency. Therefore,
Correct understanding of these two concepts will help you recover the database correctly.
For RMAN backup, The Restoration Operation can only be performed using RMAN or RMAN packages.
It is very flexible. Besides rman, it can also be completed in sqlplus. Restore and restore a database.
Use the following two simple commands
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
Command.

Restore controlfile from 'file name'
Restore controlfile from autobackup
Restore controlfile from tag = '......'
Under normal circumstances, you do not need to restore the archive logs. The recovery process will automatically find the required archive logs. Of course, we can
To 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'
5.2 In special circumstances, if the recovery directory and control file are lost, only the backup set and the backup part are left.
Is restored. 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;
/

5.3 restore check and restore 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.

SQL> recover tablespace sales test;
SQL> recover database until cancel Test
5.4 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 ';

5.5 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 to the same directory of the machine to be copied (if not the same directory, you can test
).
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;
}

5.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
Copy the backup control file from the database and start the backup database to the backup mount.
There are no data files in the database. Then, on the slave end, start the RMAN command to connect to the database (with the master database dbid
(The same). It restores the RMAN backup copied from the primary database. The last step is the same as other methods.
Management 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
6. Start to create a backup database.
RMAN> duplicate target database for standby dorecover nofilenamecheck;
The entire process includes the creation of the backup control file, starting to mount, the path conversion and number specified in the parameter file
Restore data files and archive logs.
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;

Vi. RMAN Management
6.1report command
The report command can detect the files that need to be backed up, the files that can be deleted, and the files that can be obtained.
Information, such
Report all data file objects that can be backed up in the database
Report Schema
Or
RMAN> report schema at time 'sysdate-14 ';
RMAN> report schema at SCN 1000;
RMAN> report schema at sequence 100 thread 1;
Report the data files to be backed up
Report need backup [redundancy | days | incremental N];
Report expired data files or unavailable backup and copy
Report obsolete [orphan]
Data File information that cannot be obtained or arrived in the report
Report unrecoverable [database]
6.2 LIST Command
The list command is generally used to view backup and copy information, as shown in figure
View backup information
List backup
View backup summary information
List backup Summary
View copy information
List copy
View specific backup information
List backup of datafile 'file name'
List incarnation of database;
18
6.3 crosscheck command
Check whether the backup or copy on the disk or tape is correct, and update the backup or copy status.
If it is incorrect, it will be marked as expired (expired)
Crosscheck backup;
Crosscheck archivelog all;
Delete [noprompt] expired BACKUP command to delete expired backup
You can also use list to view the corresponding report.
List expired backup;
List expired backup summary;
6.4 DELETE command
The DELETE command can be used to delete a specified backup or to delete an obsolete or expired backup set.
For example, you can delete a specified backup set and backup slice.

RMAN> Delete backuppiece 101;
RMAN> Delete controlfilecopy '/tmp/control01.ctl ';
RMAN> Delete backup of tablespace users device type SBT;

Delete expired or obsolete backups

RMAN> Delete expired backup;
RMAN> Delete noprompt obsolete;
RMAN> Delete Obsolete redundancy = 3;
RMAN> Delete Obsolete recovery window of 7 days;

Deletes a specified backup archive.
RMAN> Delete noprompt archivelog until sequence = 300;
7. Restore the Directory
In Oracle version 9, the automatic backup of control files does not need to be used to restore directories. However, the following benefits apply to restoring directories:
· Some commands are only supported by the restored directory (for 9i, that is, the statements dedicated to restoring the Directory)
· Retain more historical backup information
· One recovery directory can manage and back up multiple target Databases
· If the control file is lost before 9i and the directory is not restored, it will be difficult to restore it.
· If the directory is not restored and the structure changes, you must be careful when restoring the directory at a time point.
· Scripts that can store backup and recovery
We can see that more backup information can be kept and multiple target databases can be conveniently managed. This can be considered when many target databases exist.

7.1 create a recovery directory
Note: The recovery Directory should not be on the same machine as the target database, and the size requirement is small.

SQL> create user RMAN identified by RMAN
2 temporary tablespace temp
3 default tablespace rcvcat
4 quota unlimited on rcvcat;
SQL> grant recovery_catalog_owner to RMAN;
RMAN> Create catalog
RMAN> Register database;

To restore a directory, run the following command to upgrade and delete the directory:

RMAN> Upgrade Catalog;
RMAN> drop Catalog;

7.2 Restore directory management
The following commands are supported to restore a directory:

{Create | upgrade | drop} catalog
{Create | Delete | replace | print} script
List Incarnation
Register database
Report schema at time
Reset Database
Resync catalog

1. resync command
Resync can synchronize information between the database and the recovery directory. In actual situations, RMAN can automatically synchronize data.
Synchronization is required under the following circumstances:
· Changes in the physical structure of databases
· Increase or change the data file size
· Tablespace Deletion
· Create and delete rollback segments
· Every 10 archived logs are generated
2. Reset command
After the target database resetlogs, You need to reset the recovery directory. The reset command is used to reset the recovery directory.
7.3 restore the directory View
The recovery directory itself has a set of views for storing the target database and backup information, as shown in figure
Restore the view of a directory
Rc_database
Rc_datafile
Rc_stored_script
Rc_stored_script_line
Rc_tablespace
You can run the following command to view related information:
Select * From rc_database;
7.4 storage scripts
Storage script

RMAN> creata script level0backp {
Backup
Incremental level 0
Format '/u01/db01/backup/% U'
Filesperset 5
Database Plus archivelog Delete input;
SQL 'alter database archive log current ';
}

Execute scripts
RMAN> run {execute script level0backup ;}
Update script
RMAN> replace script level0backup {
......
}
Delete script
RMAN> Delete script level0backup;
View scripts
RMAN> Print script level0backup;

A Practical script, including shell scripts for backing up RAC databases and archiving logs

[Oracle @ dB worksh] $ more rmanback. Sh
#! /Bin/sh
# Set env
Export ORACLE_HOME =/opt/Oracle/product/9.2
Export oracle_sid = db2in1
Export nls_lang = "american_america.zhs16gbk"
Export Path = $ path: $ ORACLE_HOME/bin:/sbin:/usr/sbin
Echo "------------------------------- start -----------------------------"; Date
# Backup start
$ ORACLE_HOME/bin/RMAN <connect target
Delete noprompt obsolete;
Backup database include current controlfile format '/rmanback/DB2/% u _ % S. Bak' filesperset = 2;
Run {
Allocate channel node_c1 device type disk connect 'sys/pass @ db1in1 ';
Allocate channel node_c2 device type disk connect 'sys/pass @ db2in2 ';
SQL 'alter system archive log current ';
Backup archivelog all Delete input format'/rmanback/DB2/% u _ % S. Bak 'filesperset = 5;
}
List backup;
Exit;
EOF
Echo "------------------------------ end ------------------------------"; Date

Article Source: http://www.diybl.com/course/7_databases/oracle/Oracleshl/2008926/145854.html

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.