Oracle Rman Quick Start Guide

Source: Internet
Author: User
Tags format execution file system connect variables variable thread oracle database
oracle| Quick Start Preface
This article mainly introduces the common methods of Rman, including some of the author's own experience, the experiment is basically all in the win 2K and Oracle 8.1.6 Environment Test success (because this environment is relatively easy to implement).

This article for reference to some of the online experts related articles, I hope the heroes do not take offense, here thanks.

This article was written mainly during a business trip to Beijing. Back home after modification, time is more hasty, at the same time because space is limited, some technical details can not cover, only hope to help beginners to the role, want to really master Rman, must undergo a long period of practice to hone can, In particular, it is necessary to obtain valuable troubleshooting experience in engineering.
1. What is Rman
Rman can be used to back up and restore database files, archive logs, and control files. It can also be used to perform complete or incomplete database recovery.

Note: Rman cannot be used to back up initialization parameter files and password files.

Rman initiates the Oracle server process on the database for backup or restore. Backup, restore, and recovery are driven by these processes.

Rman can be controlled by the OEM's backup Manager GUI, but this article does not focus on the discussion.
2. Terminology Professional Vocabulary Interpretation 2.1. Backup sets back up collection
The Backup collection has the following attributes: One or more data files or archive logs saved in Oracle proprietary format there is a complete collection of all the backup slices that make up a full or incremental backup
2.2. Backup pieces back-up Slice
A backup set consists of several backup slices. Each backup slice is a separate output file. The size of a backup slice is limited, and if there is no size limit, the backup set is made up of only one backup slice. The size of the backup slice cannot be greater than the maximum file length supported by the file system being used.
2.3. Image copies mirrored backup
A mirrored backup is a backup of a stand-alone file (data file, archive log, control file). It's very similar to operating system-level file backups. It is not a backup set or backup slice, nor is it compressed.
2.4. Full backup sets fully backed up collection
A full backup is a backup of a block of data used in one or more data files. Data blocks that are not used are not backed up, that is, Oracle makes a compression of the backup set.
2.5. Incremental backup sets incremental backups collection
An incremental backup is a block of data that is backed up by one or more data files since it was last backed up at the same level or at a lower level. As with a full backup, incremental backups are also compressed.
2.6. File multiplexing
Different data blocks for multiple data files can be mixed back up in one backup set.
2.7. Recovery Catalog resyncing Recovery directory synchronization
When you use the Recovery Manager to perform the backup, copy, restore, or switch commands, the recovery directory is automatically updated, but the log and archived log information is not automatically recorded in the recovery directory. Directory synchronization is required. Synchronize using the Resync Catalog command.

Rman>resync Catalog; RMAN-03022: Compiling command: resyncRMAN-03023: Executing command: resyncRMAN-08002: Starting resyncRMAN-08004 Full Recovery directory: complete resync
3. Restore Directory 3.1. The concept of the recovery catalog
The recovery directory is the warehouse used and maintained by Rman to place backup information. Rman uses recovered directory-recorded information to determine how to perform the required backup recovery operations.

The recovery directory can exist in the plan for the Oracle database.

Although the recovery directory can be used to back up multiple databases, it is recommended that you create a separate database for the recovery catalog database.

The recovery directory database cannot use the recovery directory to back itself up.
3.2. Create a recovery directory
The first step is to create a table space for the recovery directory in the catalog database:

sql> Create tablespace rman_ts datafile "d:\oracle\oradata\rman\rman_ts.dbf" size 20M; table space created.

The second step is to create an Rman user in the catalog database and authorize:

Sql> create user Rman identified by rman default tablespace rman_ts temporary tablespace temp Quota unlimited on rman_t s; the user has created. Sql> Grant Recovery_catalog_owner to Rman; the authorization was successful. Sql> Grant Connect, resource to Rman;

Step three, create a recovery directory in the catalog database

C:\>rman Catalog Rman/rman Recovery manager: Version 8.1.6.0.0-productionrman-06008: Connecting to the Recovery directory database RMAN-06428: The recovery directory is not installed Rman>create Catalog Tablespace rman_ts; RMAN-06431: Restore directory created

Note: Although the use of Rman does not necessarily require recovery of the directory, it is recommended. Because most of the information recorded in the recovery directory can be documented by the control file, Rman uses this information when restoring the database. Not using the recovery directory will limit backup recovery operations.
3.3. Advantages of using the recovery catalog
can store scripts;

Record a long time backup recovery operation;
4. Start Rman
Rman is an interactive command-line interface, or it can be run from Enterprise Manager.

To use the following example, check the environment first:

The target database is called "his" and has the same TNS alias user Rman has been granted "Recovery_catalog_owner" Privil   The connection user for the Eges target database is a internal account, or a different SYSDBA type account number is connected to the recovery catalog database is called "Rman" and has the same TNS alias The schema containing the recovery catalog is "Rman" (same password)

Before using Rman, set the Nls_date_format and Nls_lang environment variables, many of the output results of the Rman List command are date-time related, which is also important when the user wants to perform a time-dependent recovery effort.

The following example is a demonstration of an environment variable:

Nls_lang=simplified Chinese_china. ZHS16GBKNLS_DATE_FORMAT=DD-MON-YYYY HH24:MI:SS

To ensure that Rman can connect to the recovery directory when it is used, the recovery directory database must be open, the target database should be at least started (unmount), or Rman will return an error and the target database must be placed in archive mode.
4.1. Use Rman with no recovery directory
Set the oracle_sid of the target database to perform:

% Rman nocatalogrman> Connect targetrman> connect target internal/<password> @his
4.2. Use Rman with recovery directory
% Rman rman_ts rman/rman@rmanrman> connect target% rman rman_ts rman/rman@rman target internal/<password> @his
4.3. Using Rman
Once connected to the target database, you can execute the specified Rman command through an interactive interface or a previously stored script, and here is an instance of using the Rman Interactive interface:

rman> Resync Catalog; RMAN-03022: Compiling command: resyncRMAN-03023: Executing command: resyncRMAN-08002: Starting resyncRMAN-08004 Full Recovery directory: complete resync

To use an instance of a script:

rman> Execute script alloc_1_disk;

To create or replace stored scripts:

rman> Replace script Alloc_1_disk {2> allocate channel D1 type disk; 3>}

5. Register or unregister the target database

5.1. Register the target database

Database status:

Restore Directory Status: Open

Target database: Loading or opening

The target database must be registered in the recovery directory before using Rman for the first time:

The first step is to start the recovery manager and connect to the target database:

C:\>rman Target Internal/oracle@his Catalog Rman/rman@rman Recovery manager: Version 8.1.6.0.0-productionrman-06005: Connect to the target database: his ( dbid=3021445076) RMAN-06008: Connecting to the Recovery directory database

The second step is to register the database:

rman> Register database; RMAN-03022: Compiling command: registerRMAN-03023: Executing command: registerRMAN-08006: Registering database in recovery directory RMAN-03023: executing command: Full RESYNCRMAN-08002: Starting Full recovery directory resyncRMAN-08004: Complete all resync

5.2. Unregister the target database

Rman provides a logoff tool called the Dbms_rcvcat Toolkit, and note that once you log off the target database, you cannot recover the database by using the backup set contained in the recovery directory.

In order to log off the database, you need to obtain the database identification code (DB_ID) and database key values (Db_key). When you connect to the target database, you will get db_id.

C:\>rman Target Internal/oracle@his Catalog Rman/rman@rman Recovery manager: Version 8.1.6.0.0-productionrman-06005: Connect to the target database: his ( dbid=3021445076) RMAN-06008: Connecting to the Recovery directory database
Where dbid=3021445076, using the dbid=3021445076 query database key value code, connect to the target database, query DB table:
Sql> select * from DB; Db_key db_id curr_dbinc_key----------------------------------1 3021445076 2

Get Db_key=1 so that the target database db_key=1,dbid=3021445076, use the DBMS_RCVCAT Toolkit with two values to unregister the database:

Sql> Execute Dbms_rcvcat.unregisterdatabase (1,3021445076);P L/sql process completed successfully.

At this point, the logoff database operation completes.
6. Operation of existing backups 6.1. Join the Catalog Database
Database status:

Recovery directory: Open

Target database: Loading or opening

If you have backup data that was previously created in the 8.x version that you want to register with the target database, you can add it to the recovery directory manually as follows

rman> catalog Datafilecopy "/oracle/.../system01.dbf";

Use the following command to display the files contained in the recovery directory

rman> list copy of database;

6.2. Delete from the catalog database

First step: View backup information:

Rman>list backup; RMAN-03022: Compiling command: List

Backup set list

Keyword Recid Mark LV collection Tag collection count finish-----------------------------------------------------------------------1104 2 50136445 5 0 501364446 2 June-August-03

Backup Segment List

Keyword pc# cp# state completion time segment name----------------------------------------------------------------------1106 1 1 AVAILABLE June-August -03 D:\ORACLE\ORA81\DATABASE\02EU4DMU_1_1

Data files include lists

File name LV type Check Point SCN checkpoint time----------------------------------------------------------------------3 D:\ORACLE\ORADATA\HI S\users01. DBF 0 Full 160052 June-August-03

The backup set has a keyword of 1104.

Step Two: Define the Delete channel:

Rman>allocate channel for delete type disk; RMAN-03022: Compiling command: allocateRMAN-03023: Executing command: allocateRMAN-08030: Allocated channel: deleteRMAN-08500: Channel delete:sid=19 devtype= DISK

Step three: Delete the backupset backup set

Rman>change backupset 1104 Delete; RMAN-03022: Compiling command: changeRMAN-08073: Backup segment deleted RMAN-08517: Backup segment Handle=d:\oracle\ora81\database\02eu4dmu_1_1 recid=2 STAMP=50 1364447rman-03023: Executing command: Partial resyncRMAN-08003: Starting part of the recovery directory resyncRMAN-08005: Completing the section resync

Note: The partial execution of a command to delete a backup set, backup slice, or maintain a recovery directory requires specifying the channel first, such as:

Rman>allocate channel for delete type disk; Rman>allocate channel for maintenance type disk;
7. Backup in non-archive mode
Database status:

Recovery directory: Open

Target database: Routine startup or database loading

The recovery directory database needs to be opened and the target database must be started (or loaded). Because the target database is not in archive mode, the database cannot be opened when a backup recovery operation is in progress. You cannot place a tablespace on hot backup mode equivalent to a file system level copy, and if the database is open in a non-archive mode, it cannot be backed up by a data file.
7.1. Full database backup
Rman> Run {2> # Backup the complete database to disk 3> allocate channel DEV1 type disk; 4> backup 5> full 6> tag full_db_backup 7> format "/oracle/backups/db_t%t_s%s_p%p" 8> (database); 9> release channel Dev1; 10>}

Line 3&9:see: Indicates that the behavior comment Line (# is an annotation character) is fully prepared for the section 15-channels Channel definition 5:full backup (default if full or incremental not specified) Copy mode (default mode) 6:meaningful string (<=30 chars) (Backup set identity, <=30 characters) 7:filename to use for backup pieces, including Substitutio n variables. The file name used by the backup slice, which can contain a substitution variable. 8:indicates all files including Controlfiles are to is backed up indicates that all data files are backed up including control files

Display the backup set information that is documented in the recovery directory by using the following command:

Rman> list backupset of database;
7.2. Backup table Space
Rman> Run {2> allocate channel DEV1 type disk; 3> backup 4> tag tbs_users_read_only 5> format "/oracle/bac kups/tbs_users_t%t_s%s "6> (tablespace users) 7>}

Use the following command to display the backup information for the table in the recovery directory:

Rman> list backupset of tablespace users;

Assuming that the users table space is placed in the Read only table space after the backup, then the entire library backup will not be able to back up the tablespace, and for this purpose, you can specify "Skip ReadOnly" in future backups.

Note that the target database does not need to be open, as long as it is loaded, because the information in the tablespace is stored in the control file.
7.3. Backing up individual data files
Rman> Run {2> allocate channel DEV1 type "Sbt_tape" 3> backup 4> format "%d_%u" 5> (datafile "/oracle/dbs") /SYSBIGDB.DBF "); 6> release channel Dev1; 7>}

Line: Use MML (Media Manager layer) to assign a tape drive, you must specify a type of sbt_tape;

Note that the identity is empty because no identity is specified;

Use the following command to display the table space that is backed up in the recovery directory:

Rman> list backupset of datafile 1;
7.4. Backing up data files
Rman> Run {2> allocate channel DEV1 type "Sbt_tape" 3> copy datafile "to"/oracle/dbs/temp.dbf /TEMP.DBF "; 4> release channel Dev1; 5>}

Use the following command to display the copy of a file in the recovery directory:

rman> list copy of datafile "/ORACLE/DBS/TEMP.DBF";

Copying data files is not the same as backing up data files, and a copy of the data file is a mirror image of the file. A backup of the file produces a backup set.
7.5. Backup control Files
Rman> Run {2> allocate channel DEV1 type "Sbt_tape" 3> backup 4> format "cf_t%t_s%s_p%p" 5> tag Cf_monday _night 6> (current controlfile); 7> release channel Dev1; 8>}

Note: A full database backup will automatically back up the control files.
8. Backup in Archive mode
Database status:

Recovery directory: Open

Target database: Routine started, database loaded or opened

The backup operation uses the same commands as the non-archive mode.
8.1. Backing up archived logs backup archive log
The following script backs up the archive log:

Rman> Run {2> allocate channel DEV1 type disk; 3> backup 4> format "/oracle/backups/log_t%t_s%s_p%p" 5> (A Rchivelog all) 6> release channel Dev1; 7>}

The following script archive logs from # to 100:

Rman> Run {2> allocate channel DEV1 type disk; 3> backup 4> format "/oracle/backups/log_t%t_s%s_p%p" 5> (A Rchivelog from logseq=90 until logseq=100 thread 1); 6> release channel Dev1; 7>}

The following script backs up the archived logs generated within 24 hours and automatically deletes the archive log after the backup is complete. If the backup fails, the archive log is not deleted.

Rman> Run {2> allocate channel DEV1 type disk; 3> backup 4> format "/oracle/backups/log_t%t_s%s_p%p" 5> (A Rchivelog from time "sysdate-1" all delete input); 6> release channel Dev1; 7>}

Use the following command to display the archive log in the recovery directory:

Rman> list backupset of Archivelog all;

Note: When Rman finds an archive log, it backs up the specified log and does not return an error message if the log cannot be found.
8.2. Backing up the online logs back up the log
The online logs cannot be backed up with Rman and must be archived first.

To achieve this, you must execute the following SQL statement in Rman:

Rman> Run {2> allocate channel DEV1 type disk; 3> SQL ' alter system archive log current '; 4> backup 5> for Mat "/oracle/backups/log_t%t_s%s_p%p" 6> (Archivelog from, "sysdate-1" all delete input); 7> release channel Dev1; 8>}

The above script can be executed after completing a full online database backup, ensuring that all redo logs can restore the database to a consistent state.

Note: Archive log backup sets cannot be identified.
9. Incremental backup
N-level incremental backup backs up all changed chunks of data since the most recent n-level or smaller level. There are two types of incremental backups, one is a cumulative incremental backup, and the other is a non cumulative incremental backup.

A cumulative incremental backup includes all the changed blocks of data since the last backup at a lower level.

Non-cumulative incremental backups include blocks of data that have been modified since the previous backup at the sibling or lower level.
9.1. Level 0--the foundation of an incremental backup strategy
Level 0 is the foundation of an incremental backup strategy--the basis of the incremental backup strategy

Rman> Run {2> allocate channel DEV1 type disk; 3> backup 4> incremental Level 0 5> Filesperset 4 6> for Mat "/oracle/backups/sunday_level0_%t" 7> (database); 8> release channel Dev1; 9>}

Line#4:0-level Backup 5: Defines the maximum number of files per backupset

Using the list statement, the "type" will display "incremental" in the listing display of the database backup set, and the LV column will display "0".
9.2. Cases with incremental backups
A typical incremental backup case is as follows: Sunday evening-level 0 backup performed Monday evening-level 2 backup performed Tuesday night-level 2 backup performed Wednesday evening-Level 1 backup performed Thursday night-level 2 backup performed Friday night-level 2 backup performed Saturday night-level 2 B Ackup performed Sunday night-level 0 backup performed
10. Recovery
The recovery case is as follows:
10.1. Database Open,datafile deleted the file was deleted when it was opened
The data file was deleted when the database was opened. There are two ways to recover an open database: Restore a data file or a tablespace. The following two examples show this method:

(a) datafile recovery data File Recovery

Rman> Run {2> allocate channel DEV1 type disk; 3> SQL "alter TABLESPACE users offline immediate"; 4> restore DataFile 4; 5> recover datafile 4; 6> SQL "alter tablespace users online"; 7> release channel Dev1; 8>}

(b) tablespace Recovery table Space Recovery

Rman> Run {2> allocate channel DEV1 type disk; 3> SQL "alter TABLESPACE users offline immediate"; 4> restore Tablespace users; 5> Recover tablespace users; 6> SQL "alter tablespace users online"; 7> release channel Dev1; 8>}

Note: If you restore the system tablespace files, the database must be closed because the system tablespace cannot be taken offline.
10.2. Complete Restore (lost online redo) and rollforward-database closed full restore (lost online logs) and roll forward-database shutdown
Rman> Run {2> allocate channel DEV1 type disk; 3> set until logseq=105 thread=1; 4> restore Controlfile to "/ Oracle/dbs/ctrltargdb.ctl "; 5> replicate controlfile from "/oracle/dbs/ctrltargdb.ctl"; 6> Restore Database; 7> SQL "ALTER DATABASE mount"; 8> Recover database; 9> SQL "ALTER DATABASE open Resetlogs"; 10> release channel Dev1; 11>}

NOTES: The set until command indicates the recovery to the specified log file. This is important when the data file is restored, or Rman will attempt to recover the most recent data file, which may have been before the specified log. "Replicate Controlfile" copies the restored control files to the Init.ora specified control file.

If the database is opened using with resetlogs, you need to register the changed database with the Reset DB command. It is strongly recommended that you make a full database backup after you open the database using the Resetlogs command.
10.3. Restore a subset of the data file, complete recovery
Rman> Run {2> allocate channel DEV1 type disk; 3> SQL "ALTER DATABASE mount"; 4> restore datafile 2; 5> re Store DataFile 3; 6> restore Archivelog all; 7> Recover database; 8> SQL "ALTER DATABASE OPEN"; 9> release channel Dev1; 10>}
11. Script
To create or replace a script:

Rman> Create script Alloc_disk {2> # Allocates one disk 3> allocate channel DEV1 type disk; 4> Setlimit Chann El dev1 Kbytes 2097150 maxopenfiles readrate 200; 5>}rman> Replace script rel_disk {2> # releases disk 3> release channel DEV1; 5>}rman> Replace Script Backup_db_full {2> # Performs a complete backup 3> execute script alloc_disk; 4> backup 5> ..... 6> Execute script rel_disk; 7>}

The first two scripts are used to allocate and recycle channels, respectively.

The Alloc_disk script also specifies the maximum number of megabytes for the backup slice, the maximum amount of input files that can be opened concurrently at the time of the backup, and the maximum number of data buffers that read each input file per second.

The third script calls the two scripts previously stored for database backups.

To run a demo of storage scripts:

Rman> Run {2> execute script backup_db_full; 3>}

Note: The stored script must be in {.... Call in the command.
Corruption detection
Rman can back up data files that contain corrupted blocks of data, and query views v$back_corruption and V$copy_corruption can obtain information about bad data.

You can avoid a backup failure by setting the set Maxcorrupt to skip the specified number of bad blocks.

rman> Replace script Backup_db_full {2> # Performs a complete backup 3> execute script alloc_disk; 4> set Max Corrupt for datafile 1 to 0; 5> backup 6> ..... 7> Execute script rel_disk; 8>}

The above script maxcorrupt for DataFile 1 to 0 is set to 0, so if an error block is found in data file 1, the above script execution fails.
13. Channel
One channel is a connection between Rman and the target database, the "Allocate channel" command starts a server process in the target database, and the I/O type used by the server process to perform a backup or restore operation must be defined

Channel control commands can be used to: control the O/S resources that Rman uses influence parallelism specifies the limit of the I/O bandwidth (setting the limit read rate parameter) to define the size of the backup slice (set limit Kbytes) Specify the limit for the current open file (set Limi T maxopenfiles)
& List commands14.1. List
The list command queries the recovery directory and produces the formatted query content:

Rman> list backupset of datafile 1;  Key File Type LV completion_time Ckp SCN Ckp time----------------------------------------------------------165 1 Full Oct 11:24 32022 Oct 11:24-1 Full Oct 14:27 52059 Oct 14:26 219 1 Full Oct 14:31 52061 Oct 24 14: << Other entries here >> rman> list backupset of Archivelog all; Key thrd Seq Completion time---------------------------------179 1 Oct 11:26 179 1 Oct 11:26 << oth ER entries here >>
14.2.
The report command can also query the recovery directory, but the report command syntax can build instructions for more useful information, and the report command output can be saved to the message log file, but you must specify the Msglog or log option when connecting to the recovery directory.

List of files that cannot be recovered in all databases can be listed:

Rman> unrecoverable database;

Show All data files:

Rman> a schema; RMAN-03022: Compiling command: Report database schema reports file kilobytes table space RB segs name 1 121472 SYSTEM YES D:\ORACLE\ORADATA\HIS YSTEM01. DBF 2 327680 RBS YES D:\ORACLE\ORADATA\HIS\RBS01. DBF 3 110592 USERS NO D:\ORACLE\ORADATA\HIS\USERS01. DBF 4 73728 TEMP NO D:\ORACLE\ORADATA\HIS\TEMP01. DBF 5 12288 TOOLS NO D:\ORACLE\ORADATA\HIS\TOOLS01. DBF 6 59392 INDX NO D:\ORACLE\ORADATA\HIS\INDX01. Dbf
15. Tips
Frequently synchronize the recovery directory

Confirm deletion of unwanted archive logs

Simple principle of backup strategy


Related Article

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.