Oracle RMAN Quick Start Guide

Source: Internet
Author: User
Document directory
  • 1. What is rman?
  • 2. Terminology
  • 3. Restore the Directory
  • 4. Start RMAN
  • 6. Operate on existing backups
  • 7. Backup in non-archive Mode
  • 8. Backup in archive Mode
  • 9. Incremental Backup
  • 10. Restore
  • 11. Script
  • 12. Upload uption Detection
  • 13. Channel
  • 14. Report & LIST commands
  • 15. Tips
Oracle RMAN Quick Start Guide

Preface

This article mainly introduces common methods of RMAN, including the author's experience, the experiment is also basically successful in Windows 2 K and Oracle 8.1.6 environments (because this environment is easier to implement ).

This article draws on some articles related to experts on the Internet. I hope you will not be surprised. I would like to thank you here.

This article was written during a business trip in Beijing. After returning home, I sorted out and modified it. The time was too short. At the same time, due to limited space, some technical details could not be covered one by one, only hope to help the novice get started, and to really master RMAN, it is necessary to go through a long period of practical training, especially in the project to obtain valuable troubleshooting experience.

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 full or incomplete database recovery.

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

RMAN starts the Oracle server process on the database for backup or restoration. Backup, restoration, and recovery are driven by these processes.

RMAN can be controlled by the OEM Backup Manager GUI, but this article does not focus on it.

2. Terminology 2.1. Backup sets Backup set

Backup sets have the following features:
Contains one or more data files or archived logs.
Save in oracle proprietary format
There is a complete set of all backup slices
Create a full backup or Incremental Backup

2.2. Backup pieces Backup parts

A backup set consists of several backup slices. Each backup file is a separate output file. The size of a backup slice is limited. If there is no size limit, the backup set is composed of only one backup slice. The size of the backup file cannot exceed the maximum file length supported by the file system.

2.3. Image copies Image backup

Image backup is a backup of independent files (data files, archived logs, and control files. It is similar to file backup at the operating system level. It is neither a backup set nor a backup part, nor is it compressed.

2.4. Full backup sets Full backup set

Full backup is a backup of data blocks used in one or more data files. Unused data blocks are not backed up. That is to say, oracle compresses the backup set.

2.5. Incremental backup sets Incremental backup set

Incremental Backup refers to the data block that has been modified since the last or lower-level backup of one or more data files. Same as full backup, Incremental backup is also compressed.

2.6. File multiplexing

Data blocks of different data files can be backed up in a backup set together.

2.7. Recovery catalog resyncing resume directory synchronization

When you use the recovery manager to execute the backup, copy, restore, or switch commands, the recovery directory is automatically updated, but information about logs and archived logs is not automatically recorded in the recovery directory. Directory synchronization is required. Use the resync catalog command for synchronization.

RMAN> resync catalog; RMAN-03022: compiling command: resync RMAN-03023: Executing command: resync RMAN-08002: Starting resync RMAN-08004 for all recovery directories: finishing all resync
3. Restore directory 3. 1. Restore the concept of directory

The recovery directory is a warehouse used and maintained by RMAN to store backup information. RMAN uses the information recorded in the recovery directory to determine how to perform the required backup and recovery operations.

The recovery directory can be stored in the ORACLE database plan.

Although the recovery directory can be used to back up multiple databases, we recommend that you create a separate database for the recovery directory database.

Restoring a directory database cannot use restoring directory backup itself.

3. 2. Create a recovery directory

Step 1: Create a tablespace in the directory database to restore the directory:

SQL> create tablespace rman_ts datafile "d: \ oracle \ oradata \ rman \ rman_ts.dbf" size 20 M; the tablespace has been created.

Step 2: Create an RMAN user in the directory database and authorize the user:

SQL> create user rman identified by rman default tablespace rman_ts temporary tablespace temp quota unlimited on rman_ts; the user has created. SQL> grant recovery_catalog_owner to rman; authorization successful. SQL> grant connect, resource to rman; authorization successful.

Step 3: Create and restore a directory in the directory database

C: \> rman catalog rman/rman recovery MANAGER: Version 8.1.6.0.0-Production RMAN-06008: connect to recovery catalog Database RMAN-06428: Recovery catalog RMAN> create catalog tablespace rman_ts not installed; RMAN-06431: restore directory created

Note: Although RMAN does not have to be used to restore the directory, we recommend that you use it. Because most of the information recorded in the recovery directory can be recorded through the control file, which RMAN uses when restoring the database. If you do not use the recovery directory, the backup recovery operation is limited.

3. 3. Advantages of directory Restoration

Scripts can be stored;

Records a long period of backup and recovery operations;

4. Start RMAN

RMAN is the interactive command line processing interface, and can also be run from the Enterprise Manager.

To use the following instances, check the environment compliance first:

The target database is called "his" and has the same TNS alias
User rman has been granted "recovery_catalog_owner" privileges
The target database connection user is an internal account or another SYSDBA account.
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 NL2005-2-28_FORMAT and NLS_LANG environment variables, and the output results of many rman list commands are date-time-related, this is also important for users to perform time-based recovery.

The following is an example of environment variables:

NLS_LANG = SIMPLIFIED CHINESE_CHINA.ZHS16GBK
NL2005-2-28_FORMAT = DD-MON-YYYY HH24: MI: SS

To ensure that RMAN can be used to connect to the recovery directory, the recovery directory database must be opened, and the target database must at least be STARTED (unmount). Otherwise, RMAN will return an error, and the target database must be placed in archive mode.

4. 1. Use RMAN without recovery directory

Set the ORACLE_SID of the target database and run the following command:

% rman nocatalog RMAN> connect target RMAN> connect target internal/<PASSWORD>@his
4. 2. Use RMAN with recovery directory
% rman rman_ts rman/rman@rman RMAN> connect target % rman rman_ts rman/rman@rman target internal/<PASSWORD>@his
4. Use RMAN

Once connected to the target database, you can run the specified RMAN command through the interactive interface or the previously stored script. The following is an example of using the RMAN interactive interface:

RMAN> resync catalog; RMAN-03022: compiling command: resync RMAN-03023: Executing command: resync RMAN-08002: Starting resync RMAN-08004 for all recovery directories: finishing all resync

Example of script:

RMAN> execute script alloc_1_disk;

Scripts for creating or replacing storage:

RMAN> replace script alloc_1_disk { 2> allocate channel d1 type disk; 3> }

5. Register or log out of the target database

5. 1. register the target database

Database status:

Restore directory status: Open

Target Database: load or open

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

Step 1: 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-Production RMAN-06005: connect to target database: HIS (DBID = 3021445076) RMAN-06008: connect to recover directory database

Step 2: register the database:

RMAN> register database; RMAN-03022: compiling command: register RMAN-03023: Executing command: register RMAN-08006: database RMAN-03023 registered in recovery Directory: Executing command: full resync RMAN-08002: starting resync RMAN-08004 for all recovery directories: completing all resync

5. log out of the target database

RMAN provides a deregister tool called DBMS_RCVCAT toolkit. Once the target database is deregistered, you cannot use the backup set contained in the recovery directory to recover the database.

To log out of the database, you need to obtain the database ID code (DB_ID) and database key value (DB_KEY ). DB_ID is obtained when you connect to the target database.

C: \> rman target internal/oracle @ his catalog rman/rman @ rman recovery MANAGER: Version 8.1.6.0.0-Production RMAN-06005: connect to target database: HIS (DBID = 3021445076) RMAN-06008: connect to recover directory database

DBID = 3021445076, use DBID = 3021445076 to query the database key value code, connect to the target database, and query the database table:

SQL> select * from db; DB_KEY DB_ID CURR_DBINC_KEY ---------- ---------- -------------- 1 3021445076 2

Obtain DB_KEY = 1. In this way, the target database DB_KEY = 1 and DBID = 3021445076 can be deregistered by using the DBMS_RCVCAT toolkit with two values:

SQL> execute dbms_rcvcat.unregisterdatabase (); PL/SQL process completed successfully.

So far, the database logout operation is complete.

6. Operate the existing backup 6. 1. Join the directory database

Database status:

Restore directory: Open

Target Database: load or open

If you want to register the backup data created before version 8. X to the target database, you can manually add it to the recovery directory as follows:

RMAN> catalog datafilecopy "/oracle/ .... /system01.dbf"; 

Run the following command to display the files contained in the recovery directory:

RMAN> list copy of database;

. Delete from the directory database

Step 1: view the backup information:

RMAN> List backup; RMAN-03022: compiling command: List

Backup set list

Keyword recid mark LV set mark set count completion time ------- ---------- -- ---------- ---------------------- 1104 2 501364455 0 501364446 2 06-8 month-03

Backup segment list

Keyword PC # cp # status completion time segment name ------- --- ---------------------------------------------- 1106 1 available 06-8 month-03 D: \ oracle \ ora81 \ database \ 02eu4dmu_1_1

Data File List

File Name LV type checkpoint SCN checkpoint time ---- ----------------------------------- -- ---- ----------------- 3 D: \ oracle \ oradata \ His \ users01.dbf 0 full 160052 06-8-03

The keyword of the Backup set is 1104.

Step 2: Define the delete channel:

RMAN> allocate channel for delete type disk; RMAN-03022: compiling command: allocate RMAN-03023: Executing command: allocate RMAN-08030: allocated channel: delete RMAN-08500: channel delete: sid = 19 devtype = DISK

Step 3: delete the backupset backup set

RMAN> change backupset 1104 delete; RMAN-03022: compiling command: change RMAN-08073: deleted backup segment RMAN-08517: Backup segment handle = D: \ ORACLE \ ORA81 \ DATABASE \ 02EU4DMU_1_1 recid = 2 stamp = 50 1364447 RMAN-03023: Executing command: partial resync RMAN-08003: Starting resync RMAN-08005 for partial recovery directories: Completing partial resync

Note: If you want to delete backup sets, backup slices, or maintain the recovery directory, you must specify a channel, for example:

RMAN>allocate channel for delete type disk; RMAN>allocate channel for maintenance type disk;
7. Backup in non-archive Mode

Database status:

Restore directory: Open

Target Database: routine startup or Database loading

To recover a directory database, you must open it. The target database must be started (or loaded ). Because the target database is not in archive mode, the database cannot be opened during backup and recovery. You cannot store tablespaces in hot backup mode for file system-level copying. If the tablespace is not in archive mode, data files cannot be backed up when the database is open.

. 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 #
2: indicates the behavior of the comments line (# Is the annotator)
3 & 9: See section 15-Channels Channel Definition
5: Full backup (default if full or incremental not specified) Full backup mode (default mode)
6: Meaningful string (<= 30 chars) (Backup set ID, <= 30 characters)
7: Filename to use for backup pieces, including substitution variables. The name of the backup file, which can contain replace variables.
8: Indicates all files including controlfiles are to be backed up Indicates that all data files, including control files, are backed up.

Run the following command to display the backup set information in the recovery directory:

RMAN> list backupset of database;
. Backup tablespace
RMAN> run { 
2> allocate channel dev1 type disk; 
3> backup 
4> tag tbs_users_read_only 
5> format "/oracle/backups/tbs_users_t%t_s%s" 
6> (tablespace users) 
7> }

Run the following command to display the backup information of the table in the recovery directory:

RMAN> list backupset of tablespace users;

Assume that the USERS tablespace is set as READ-ONLY tablespace after backup, and the tablespace will not be backed up after full database backup. To achieve this goal, you can specify "skip readonly" in future backups ".

Note: The target database does not need to be opened, but only needs to be loaded, because the tablespace information is stored in the control file.

. Back 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 #
2: Use MML (media manager layer) to allocate a tape drive. The type must be SBT_TAPE;

Note: because no ID is specified, the ID is empty;

Run the following command to display the tablespace backed up in the recovery directory:

 RMAN> list backupset of datafile 1;
7. 4. Back up data files
RMAN> run { 
2> allocate channel dev1 type "SBT_TAPE"; 
3> copy datafile "/oracle/dbs/temp.dbf" to "/oracle/backups/temp.dbf"; 
4> release channel dev1; 
5> }

Run the following command to restore the file copy in the directory:

RMAN> list copy of datafile "/oracle/dbs/temp.dbf";

Copying a data file is different from backing up a data file. copying a data file is an image of this file. File backup generates 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: Full database backup automatically backs up control files.

8. Backup in archive Mode

Database status:

Restore directory: Open

Target Database: instance startup, Database loading or opening

The commands used for backup operations are basically the same as those used in non-archive mode.

8.1. Backing up archived logs back up archive logs

The following script backs up archive logs:

RMAN> run { 
2> allocate channel dev1 type disk; 
3> backup 
4> format "/oracle/backups/log_t%t_s%s_p%p" 
5> (archivelog all) 
6> release channel dev1; 
7> }

The following script Archives logs from #90 to 100:

RMAN> run { 
2> allocate channel dev1 type disk; 
3> backup 
4> format "/oracle/backups/log_t%t_s%s_p%p" 
5> (archivelog 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. After the backup is completed, the archived logs are automatically deleted. If the backup fails, the archive log will not be deleted.

RMAN> run { 
2> allocate channel dev1 type disk; 
3> backup 
4> format "/oracle/backups/log_t%t_s%s_p%p" 
5> (archivelog from time "sysdate-1" all delete input); 
6> release channel dev1; 
7> }

Run the following command to display the archived logs in the recovery directory:

RMAN> list backupset of archivelog all;

Note: After RMAN finds the archived log, it will back up the specified log. If the log cannot be found, it will not return an error message.

8.2. Backing up the online logs to back up online logs

Online logs cannot be backed up using RMAN. They must be archived first.

To achieve this, the following SQL statement must be executed in RMAN:

RMAN> run { 
2> allocate channel dev1 type disk; 
3> sql "alter system archive log current"; 
4> backup 
5> format "/oracle/backups/log_t%t_s%s_p%p" 
6> (archivelog from time "sysdate-1" all delete input); 
7> release channel dev1; 
8> }

The above script can be executed after a complete online database backup is executed to ensure that all the redo logs can restore the database to a consistent state.

Note: The archived log backup set cannot be identified.

9. Incremental Backup

The N-level Incremental Backup backs up all the changed data blocks since the last N-level or lower-level. Incremental Backup can be divided into two types: cumulative incremental backup and non-cumulative incremental backup.

Cumulative Incremental Backup includes all changed data blocks since the last backup at a lower level.

Non-cumulative incremental backup includes the data blocks that have been changed since the previous backup at the same level or lower level.

9.1. Level 0 -- basis of Incremental backup policy

Level 0 is the basis of the incremental backup policy -- 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> format "/oracle/backups/sunday_level0_%t" 
7> (database); 
8> release channel dev1; 
9> }

Line #
4: backup at level 0
5. Define the maximum number of files for each backupset.

Use the LIST statement to view the LIST of Database Backup sets. The "type" column displays "Incremental" and "LV" column displays "0 ".

9.2. Incremental Backup case

A typical Incremental Backup case is as follows:
Sunday evening-level 0 backup completed MED
Monday evening-level 2 backup completed MED
Tuesday evening-level 2 backup completed MED
Wednesday evening-level 1 backup completed MED
Thursday evening-level 2 backup completed MED
Friday evening-level 2 backup completed MED
Saturday evening-level 2 backup completed MED
Sunday evening-level 0 backup completed MED

10. Restore

The recovery case is as follows:

10.1. Database open, datafile deleted when the database is opened, the file is deleted

The data file is deleted when the database is opened. There are two ways to restore the opened database: restoring data files or tablespaces. The method is shown in the following two instances:

(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 Tablespace Restoration

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 file, 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 restoration (loss of online logs) and rollback-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 that the log file is restored to the specified log file. This is important when the data file is restored. Otherwise, RMAN will try to restore the most recent data file, which may be before the specified log.
"Replicate controlfile" copies the restored control file to the control file specified by INIT. ORA.

If the DATABASE is opened with resetlogs, you must use the reset database command to register the changed DATABASE. After you use the RESETLOGS command to open the database, we strongly recommend that you back up the database completely.

10.3. Restore the subset of the data file and restore it completely
RMAN> run { 
2> allocate channel dev1 type disk; 
3> sql "alter database mount"; 
4> restore datafile 2; 
5> restore datafile 3; 
6> restore archivelog all; 
7> recover database; 
8> sql "alter database open"; 
9> release channel dev1; 
10> }
11. Script

Create or replace a script:

RMAN> create script alloc_disk {
2> # Allocates one disk
3> allocate channel dev1 type disk;
4> setlimit channel dev1 kbytes 2097150 maxopenfiles 32 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>... <backup commands here>
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 MB size of the backup part. the maximum number of input files that can be opened at the same time during Backup and the maximum number of data buffers for reading each input file per second.
The third script calls the two previously stored scripts for database backup.
Example of running a storage script:
RMAN> run { 
2> execute script backup_db_full; 
3> }

Note: The stored script must be called in the {... execute <script>;...} command.

12. Upload uption Detection

RMAN can back up data files that contain corrupted data blocks. query the view V $ back_partition uption and V $ copy_partition uption to obtain information about bad data.

By setting set maxcompute upt, you can skip the specified number of Bad blocks to avoid backup failure.

RMAN> replace script backup_db_full { 
2> # Performs a complete backup 
3> execute script alloc_disk; 
4> set maxcorrupt for datafile 1 to 0; 
5> backup 
6> .....
 
7> execute script rel_disk; 
8> }

The preceding script maxcompute upt for datafile 1 to 0 is set to 0. Therefore, if an error data block is found in data file 1, the above script will fail to be executed.

13. Channel

A channel is a connection between RMAN and the target database. The "allocate channel" command starts a server process in the target database, at the same time, you must define the I/O type used by the server process for backup or recovery.

The channel control command can be used:
Controls the O/S resources used by RMAN
Affect degree of Parallelism
Specify the I/O bandwidth limit (set the limit read rate parameter)
Define the size limit of the backup slice (set limit kbytes)
Specify the limit of the currently opened file (set limit maxopenfiles)

14. Report & list commands14.1. list

THE list Command queries the recovery directory and generates formatted query content:

 RMAN> list backupset of datafile 1;

Key File Type LV Completion_time Ckp SCN Ckp Time
------- ---- ------------ -- --------------- ---------- --------
165 1  Full Oct 03 11:24 32022 Oct 03 11:24
208 1  Full Oct 24 14:27 52059 Oct 24 14:26
219 1  Full Oct 24 14:31 52061 Oct 24 14:31
<< other entries here >>

RMAN> list backupset of archivelog all;

Key Thrd Seq Completion time
------- ---- ------- ---------------
179 1 94 Oct 03 11:26
179 1 95 Oct 03 11:26
<< other entries here >>
14.2. Report

The REPORT command can also query the recovery directory, but the REPORT command syntax can be used to build instructions for more useful information. The REPORT command output can be saved to the Message Log File, however, MSGLOG or LOG must be specified when the connection is restored.

You can list files that cannot be recovered in all databases:

 RMAN> report unrecoverable database;

Show all data files:

RMAN> report Schema; RMAN-03022: compiling command: Report database mode report file kilobytes tablespace RB segs name 1 121472 system yes D: \ oracle \ oradata \ His \ system01.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 synchronized recovery directory

Confirm to delete unnecessary archive logs

Simple backup policy principles

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.