Oracle RMAN Quick Start Guide

Oracle RMAN Quick Start Guide

Foreword

This article introduces the the RMAN common method, which contains some of the author’s own experiences, experiments inside all the basic WIN 2K and Oracle 8.1.6 environment test is successful (because the environment is relatively easy to implement).

This article draws on the master online article, I hope heroes do not take offense, be thanked here.

This article is mainly in Beijing during a business trip to write home after finishing modify, rush time, because of space limitations, some technical details can not be covered one by one, and only hope to help beginners, really want to skilled grasp RMAN must be a long-time practice can only be honed, especially in engineering to gain valuable experience in troubleshooting.

1 What is RMAN

RMAN can be used to backup and restore the database files, archive logs and control files. It can also be used to perform a complete or incomplete database recovery.

Note: RMAN can not be used in the the backup initialization parameter file and password file.

RMAN starts Oracle server process on the database for backup or restore. Backup, restore, recovery is driven by these processes.

RMAN can be controlled by the OEM Backup Manager GUI, but are not the focus of discussion in this article.

Terminology professional Glossary

2.1 Backup sets backup set

The backup set has the following characteristics:
Includes one or more data files or archived logs to Oracle proprietary format to save a complete backup piece collection constitute constitute a full backup or incremental backup

2.2 Backup pieces backup piece

A backup set consists of a number of backup pieces. Each backup piece is a single output file. A backup piece size is limited; If there is no size limit, the backup set is only a backup piece. File system supported by the size of the backup piece can not be greater than the maximum value of the length of the document.

Of 2.3 Image Copies mirror backup

Mirror backup separate files (data files, archive logs, control file) backup. It is very similar to the operating system level file backup. It is not a backup set or backup piece, also has not been compressed.

2.4 Full Backup sets full backup set

Full backup is a backup of one or more data files used in the data block. Have not used the data block is not backed up, that is to say, the Oracle backup set compression.

2.5. Incremental backup sets incremental backup set

Incremental backup is a backup of one or more data files have been modified since the on the same level or lower-level backup of data blocks. The same as the full backup, incremental backup compression.

2.6 File multiplexing

A plurality of different data file’s data blocks can be mixed backup in a backup set.

2.7. Recovery catalog resyncing recovery directory synchronization

Recovery Manager to perform backup, copy, restore or switch command, the recovery catalog automatically updated, but the log and archive log information is not automatically credited to the recovery catalog. The need for directory synchronization. Use the resync catalog command to synchronize.

  RMAN> resync catalog;

 RMAN-03022:'re compiling command: resync
 RMAN-03023: executing command: resync
 RMAN-08002: Starting full recovery catalog resync
 RMAN-08004: full resync complete

(3) recovery catalog

3.1 the concept of recovery catalog

The recovery catalog is used by RMAN maintenance warehouse used to place the backup information. RMAN recovery catalog records information to determine how to perform the backup and recovery operations.

The recovery catalog can exist in the ORACLE database plan.

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

Recovery catalog database recovery catalog can not use the backup itself.

3.2 Establish recovery catalog

The first step is created in the directory database recovery catalog table space:

  SQL> create tablespace rman_ts datafile "d :/ oracle / oradata / rman / rman_ts.dbf" size 20M;

 Table space has been created.

Created in the directory database RMAN user and authorization:

  SQL> create user rman identified by rman default tablespace rman_ts temporary 
   tablespace temp quota unlimited on rman_ts;

 The user has been created.

 SQL> grant recovery_catalog_owner to rman;

 Grant succeeded.

 SQL> grant connect, resource to rman;

 Grant succeeded.

The third step is created in the directory database recovery catalog

  C :/> rman catalog rman / rman

 Recovery Manager: Version 8.1.6.0.0 - Production

 RMAN-06008: connected to recovery catalog database RMAN-06428: not installed recovery catalog RMAN> create catalog tablespace rman_ts;

 RMAN-06431: recovery catalog has been created

Note: While using RMAN recovery catalog is not necessarily required, but recommended. Restore the information described in a catalog can control file to record RMAN restore the database to use this information. Do not use a recovery catalog backup and recovery operations will be limited.

3.3 The use of the advantages of recovery catalog

Can be stored in the script;

Documented long-time backup and recovery operations;

4 Start RMAN

RMAN for interactive command-line processing interface, you can also run from Enterprise Manager.

In order to use the example below, first check the environment in accordance with:

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 as internal account, or connected to the recovery catalog database is called “rman” and has the same TNS alias to other SYSDBA type account
the schema containing the recovery catalog is “rman” (same password)

Before using RMAN, set the NLS_DATE_FORMAT and NLS_LANG environment variable, the the many RMAN LIST command output is related to the time and date, and that the user wishes to perform time-based recovery is also very important.

The following example is a demonstration of the environment variable:

NLS_LANG = SIMPLIFIED CHINESE_CHINA.ZHS16GBK
NLS_DATE_FORMAT = DD-MON-YYYY HH24: MI: SS

Connected to recovery catalog RMAN recovery catalog database must be open, at least the target database STARTED (unmount), otherwise RMAN returns an error, the target database must be placed in archive mode.

4.1 Use without RMAN recovery catalog

Set the target database ORACLE_SID, run:

  % Rman nocatalog
 RMAN> connect target
 RMAN> connect target internal / <PASSWORD> @ his

4.2 Use with RMAN recovery catalog

  % Rman rman_ts rman / rman @ rman
 RMAN> connect target

 % Rman rman_ts rman / rman @ rman target internal / <PASSWORD> @ his

4.3 Using RMAN

Once connected to the target database, you can perform the specified interface or prior script stored RMAN commands Here is an instance of the RMAN interface:

 RMAN> resync catalog; RMAN-03022:'re compiling command: resync RMAN-03023: executing command: resync RMAN-08002: Starting All the Resync recovery catalog RMAN-08004: full resync complete

Use scripts instance:

  RMAN> execute script alloc_1_disk;

Create or alternative storage script:

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

Register or cancellation of the target database.

5.1 Register the target database

Database status:

The recovery catalog Status: open

Target database: load or open

The target database before the first use RMAN must be registered in the recovery catalog:

The first step 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 - Production
 RMAN-06005: connected to target database: HIS (DBID = 3021445076)
 RMAN-06008: connected to recovery catalog database

The second step, the registration database:

  RMAN> register database;
 RMAN-03022:'re compiling command: register
 RMAN-03023: executing command: register
 RMAN-08006: registered in the recovery catalog database RMAN-03023: executing command: full resync
 RMAN-08002: Starting full recovery catalog resync
 RMAN-08004: full resync complete

5.2 cancellation of the target database

The RMAN provides a canceled tools, and called DBMS_RCVCAT Kit, please note that canceled the target database will not be able to use the backup set to restore the database containing the recovery catalog.

In order to be able to cancellation of the database, you need to get database code (DB_ID) and database key (DB_KEY). Connecting to the target database will get DB_ID.

  C :/> rman target internal / oracle @ his catalog rman / rman @ rman
 Recovery Manager: Version 8.1.6.0.0 - Production
 RMAN-06005: connected to target database: HIS (DBID = 3021445076)
 RMAN-06008: connected to recovery catalog database

Dbid = 3021445076 DBID = 3021445076 query the database key code to connect to the target database, query the db table:

  SQL> select * from db;

   DB_KEY DB_ID CURR_DBINC_KEY
   ----------------------------------
   130214450762

Get DB_KEY = so, the target database DB_KEY = 1, DBID = 3021445076, the use of the two values ??use DBMS_RCVCAT Kit can be canceled database:

  SQL> execute dbms_rcvcat.unregisterdatabase (1,3021445076);
 PL / SQL procedure successfully completed.

At this point, the completion of the cancellation of database operations.

6 Operation existing backup

6.1 added to the directory database

Database status:

Recovery catalog: Open

Target database: load or open

If you want to exist the 8.x versions previously created backup data registered to the target database can be used manually added to the recovery catalog

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

Use the following command to restore the files contained in the directory

  RMAN> list copy of database;

6.2 deleted from the directory database

Step 1: Check the backup information:

  RMAN> list backup;
 RMAN-03022:'re compiling command: list

List of backup sets

  Collection of keyword Recid mark LV tag collection count is completed --------------------------------------- --------------------------------
 110,425,013,644,550 501 364 446 2 06-8 -03

Backup segment list

  Keyword Pc # Cp # state of complete time range --------------------------------------- -------------------------------
 1106 1 1 AVAILABLE 06-8 May -03 D :/ ORACLE/ORA81/DATABASE/02EU4DMU_1_1

Data files include a list of

  File Name LV Type checkpoint SCN checkpoint ---------------------------------------- ------------------------------
    3 D :/ ORACLE/ORADATA/HIS/USERS01.DBF 0 Full 160052 06-8 May -03

Backup set keyword 1104.

Step 2: Define delete channel:

  RMAN> allocate channel for delete type disk;
 RMAN-03022:'re compiling command: allocate
 RMAN-03023: is running the command: ALLOCATE
 RMAN-08030: allocated channel: delete
 RMAN-08500: channel delete: sid = 19 devtype = DISK

The third step: delete backupset backup set

 RMAN> change backupset 1104 delete; RMAN-03022: compile command: change RMAN-08073: deleted the backup segment RMAN-08517: backup piece handle = D :/ ORACLE/ORA81/DATABASE/02EU4DMU_1_1 recid = 2 stamp = 50 1364447 RMAN -03023: executing command: partial resync RMAN-08003: the Start section recovery catalog resync RMAN-08005: partially completed resync

Note: the implementation of Part delete the backup set, backup piece or maintenance recovery catalog command, you need to specify the channel, such as:

  RMAN> allocate channel for delete type disk;

 RMAN> allocate channel for maintenance type disk;

7 in the non-archive mode backup

Database status:

Recovery catalog: Open

Target database: routine is started or database loading

Recovery catalog database need to open the target database must be started (or load). Because the target database is not in archive mode, so the database can not be opened when backup recovery operations. And not tablespace in hot backup mode is equivalent to the copy of the file system level, the state of non-archive mode, open the database data files can not be backed up.

7.1 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"
    (Database);
    The 9> release channel Dev1;
   10>}

Line #
2: indicates a comment line (# comment character)
3 & 9: See section 15 – Channels channel definition
5: Full backup (default if full or incremental not specified) full backup mode (the default)
6: Meaningful string (<= 30 chars) (backup set ID <= 30 characters)
7: filename backup piece file name to use for backup pieces, including Substitution variables can be included in place of the variable.
8: Indicates all files including controlfiles are to be backed up that back up all data files include the control file

Records in the recovery catalog backup set information is displayed by 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 / backups / tbs_users_t% t_s% s"
    > (Tablespace users)
    7>}

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

  RMAN> list backupset of tablespace users;

Suppose the the USERS tablespace after a backup set to READ ONLY table space, full database backup can not back up the table space can be specified in the backup, in order to achieve this aim, the skip readonly.

Note that the target database does not need to be open, as long as the load can be, because the table space information is stored in the control file.

7.3 backup separate 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 the MML (media manager layer) to allocate the tape drive, you must specify the type SBT_TAPE;

Note that because no identification, identity is empty;

Use the following command to restore the table space backup directory:

  RMAN> list backupset of datafile 1;

7.4 backup 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>}

Use the following command to restore the copy of the files in the directory:

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

The copy of the data file and the backup data file is not the same, the data file is a copy of the file the mirror. The backup of the file to generate a backup set.

7.5 backup control file

  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: The full database backup automatic backup control file.

Backup archive mode

Database status:

Recovery catalog: Open

Target database: routine is started, the database is loaded or open

Command and non-archive mode used by the backup operation is basically the same.

8.1. Backing up archived logs backup archive log

The following script backup archive log:

  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 archive log 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 backup archive log within 24 hours, will be automatically deleted after the backup is complete archive logs. If the backup fails, the archive logs are not 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>}

Use the following command to restore the archive log directory:

  RMAN> list backupset of archivelog all;

Note: RMAN find the archive log backup the specified logs, if you can not find the log, it will not return an error message.

8.2. Backing up the online logs up online logs

The online log can not use RMAN to back up, it must be archived.

In order to achieve this, you must execute the following SQL statement: 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 perform a full online database backup, ensure that all redo log can restore the database to a consistent state.

Note: You can not identify the archive log backup set.

9 incremental backup

N-level incremental backup backs up all changes from the N-level or smaller level since data block content. Incremental backup is divided into two, one is the cumulative incremental backup, a non-cumulative incremental backup.

Cumulative incremental backup includes all changes since the backup data blocks since the last time at the lower level.

Non-cumulative incremental backup from the previous one in the same level or lower-level changes since the backup data block.

9.1 Level 0 – incremental backup strategy is based

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

Line #
4: 0 backup
5: Define the maximum number of files in each backupset

LIST statement to check the list display of the database backup set, the “type” Incremental “LV” column will display “0”.

9.2 using the incremental backup case

A typical case of incremental backups as follows:
Sunday night – level 0 backup performed
Monday night – 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 backup performed
Sunday night – level 0 backup performed

10 Recovery

Restore the case are as follows:

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

The data file is deleted when the database is opened. There are two ways to open the database restore: Restore the data file or table space. The following two examples show that the 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 ;}

(B) the tablespace Recovery tablespace 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 shut down, because the system table space can not be offline.

10.2. Complete restore (lost online redo) and rollforward – database closed completely restored (loss of an online journal) and roll forward – the database is closed

  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";
    > Recover database;
    9> sql "alter database open resetlogs";
   10> release channel Dev1>;
   11>}

Notes:
Set until “specified in the order to return to the specified log file. This point in the data file recovery is very important, otherwise RMAN will attempt to restore the most recent data files, the data files may be specified log before.
Replicate controlfile copy the restored control file INIT.ORA specified control file.

If the database using the WITH RESETLOGS open, you need to use the RESET DATABASE command to change the registration database. After opening the database with the RESETLOGS command is strongly recommended to do a full database backup.

10.3 restore data subset of the files, fully restored

  RMAN> run {
    2> allocate channel dev1 type disk;
    3> sql "alter database mount";
    4> restore datafile 2;
    > Restore datafile 3;
    6> restore archivelog all;
    > Recover database;
    8> sql "alter database open";
    The 9> release channel Dev1;
   10>}

11. Script

Create or replace the 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> ..... 
 
 
 
   
  
  
   6> execute script rel_disk;
   
  
  
   7>} 
 
 

The first two scripts were used channel of distribution and recovery.

alloc_disk script additionally specify the maximum number of megabytes of backup piece, backup can be open at the same time the maximum number of input files, and the maximum number of read data buffer for each input file per second.

The third script calls previously stored two scripts for database backup.

Demonstration to run a stored script:

  RMAN> run {
    2> execute script backup_db_full;
    >}

Note: The the stored script must {…. execute <script>; and ….} command call.

12 Corruption Detection

RMAN can back up data files contain corrupted data block query the view the V $ BACK_CORRUPTION and V $ COPY_CORRUPTION can get information on bad data.

By setting the set maxcorrupt can skip a specified number of bad blocks to avoid the backup fails.

  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>} 
 
 

At the script maxcorrupt for datafile 1 to 0 is set to 0, so if there is an error data block found in the data file 1 at the script execution will fail.

13 channels.

A channel is a connection between RMAN and the target database, allocate channel command to start a server process in the target database, you must define the server process to perform a backup or restore operation using the I / O type

Channel control command can be used:
Control RMAN to use the O / S resources affect the degree of parallelism limit read rate parameters specify the I / O bandwidth limit value (set)
Define the backup piece size limit (set limit kbytes)
Specify the current open file limit value (set limit the MaxOpenFiles),

14. Report & list commands

14.1 List

The list command queries the recovery catalog and produce formatted query:

  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

REPORT command can query the same recovery catalog, but REPORT command syntax can build more useful information instruction REPORT command output can be saved to the message log file, but must be connected to recovery catalog to specify MSGLOG or LOG option.

The list of files that can list all the database can not be restored:

  RMAN> report unrecoverable database;

Show all data files:

 RMAN> report schema; RMAN-03022:'re compiling command: report database schema report file kilobytes table space 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

Often synchronized recovery catalog

To confirm delete unwanted archive log

Backup strategy simple principles

Posted by databasesql