Oracle rman Getting Started Guide

Source: Internet
Author: User

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.
  
Due to limited space, some technical details cannot be covered one by one. I only want to help beginners, And I want to be familiar with RMAN. I have to go through a long period of practical training, in particular, it is necessary to gain valuable experience in fault solving in the project.
  
  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 for all recovery Directories
RMAN-08004: Finished all resync
  
  3. Restore the Directory
3. 1. Restore the directory Concept
  
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 been 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: connecting to recovery Catalog Database
RMAN-06428: Recovery directory Not Installed
RMAN> create catalog tablespace rman_ts;
RMAN-06431: Recovery 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 environment variables NLS_DATE_FORMAT and NLS_LANG. The output results of many rman list commands are related to the date and time, 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
NLS_DATE_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/@ 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/@ 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 for all recovery Directories
RMAN-08004: Finished 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: connecting to recovery Catalog Database
  
Step 2: register the database:
  
RMAN> register database;
RMAN-03022: compiling command: register
RMAN-03023: Executing command: register
RMAN-08006: a database registered in the recovery directory
RMAN-03023: Executing command: full resync
RMAN-08002: Starting resync for all recovery Directories
RMAN-08004: Finished 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: connecting to recovery Catalog Database
  
Where 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:

 

I. Introduction to cold backup: the cold backup database backs up all key files including data files, control files, and online REDO LOG files after the database is closed, and copies them to another location. In addition, the cold backup can also include the backup of the parameter file and password file, but the two backup types can be selected as needed ., Cold backup is actually a physical backup, a process of backing up the physical files of the database. Because cold backup must back up all the database files except the redo log, it is also a complete database backup. Its advantages and disadvantages are as follows: 1. Advantages: <1> you only need to copy files, which is a very fast backup method. <2> you only need to copy the file back to restore it to a certain time point. <3> combined with the database archiving mode, the database can be well restored. <4> the maintenance volume is small, but the security is indeed relatively high. 2. Disadvantages: <1> the database must be closed during cold backup. <2> when using cold backup separately, the database can only restore data at a specific time point. <3> If the disk space is limited, cold backup can only copy backup data to other external storage such as tape, which slows down. <4> cold backup cannot be restored by table or by user. 3. The specific backup steps are as follows: <1> Log On As a dba or privileged user and query the dynamic performance view v $ datafile and v $ controlfile to list the database data files and control files respectively.
SQL & gt; select name from v $ datafile; NAME users/u02/oradata/db01/system01.dbf/u02/oradata/db01/users/u02/oradata/db01/sysaux01.dbf/u02/oradata/db01/users01.dbfSQL & gt; select name from v $ controlfile; NAME --------------------------------------------------------------------------------/u02/oradata/db01/control01.ctl /U02/oradata/db01/control02.ctl/u02/oradata/db01/control03.ctl/u01/app/oracle/bak/control04.ctl <2> shut down the database as a DBA or privileged user. SQL & gt; conn/as sysdba; Connected. SQL & gt; shutdown normal Database closed. database dismounted. ORACLE instance shut down. <3> copy data files to a separate hard disk or disk. Control files are mirrored to each other, so you only need to copy a control file. Cp/u02/oradata/db01 /*. dbf/u01/app/oracle/bakcp/u02/oradata/db01 /*. ctl/u01/app/oracle/bak <4> Start the routine to open the database. SQL & gt; conn/as sysdba; Connected to an idle instance. SQL & gt; startup ORACLE instance started. total System Global Area 285212672 bytes Fixed Size 1218992 bytes Variable Size 83887696 bytes Database Buffers 197132288 bytes Redo Buffers 2973696 bytes Database mounted. database opened. SQL & gt;
Ii. Hot Backup: When the database is running, the archive log mode method is used to back up the database. Hot Backup requires that the database be operated in archive log mode and requires a large amount of archive space. Once the database is in archive loh mode, it can be backed up. When performing a backup, it can only be performed at the data file level or tablespace. 1. Advantages: <1> data can be backed up at the tablespace or data file level, with a short backup time. <2> Restore within seconds (to a specific point in time ). <3> restore almost all database entities. <4> recovery is fast. In most cases, it is restored when the database is still working. <5> the database is still available during Backup. 2. Disadvantages: <1> because it is difficult to maintain, you must be careful and do not allow "end with failure ". <2> If the Hot Backup fails, the result cannot be used for restoration at a time point. <3> no error is allowed. Otherwise, the consequences are serious. 3. Set the initial archive mode: Set the archive mode. The database must be in the mount rather than open state: <1> check whether the database is in archive log mode: SQL & gt; archive log list; Database log mode No Archive Mode Automatic archival Disabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 1 Current log sequence 2 <2> Start the Database in the mount status: SQL & gt; startup mount; ORACLE instance started. total System Global Area 285212672 bytes Fixed Size 1218992 bytes Variable Size 83887696 bytes Database Buffers 197132288 bytes Redo Buffers 2973696 bytes Database mounted. <3> set the database to archive: SQL & gt; alter Database archivelog; database altered. <4> open the database:
SQL & gt; alter database open; Database altered. <5> set the database to automatic archiving and run the following command: SQL & gt; alter system set log_archive_start = true scope = spfile; System altered. <6> make sure that the database is in archive mode and set automatic archiving: SQL & gt; archive log list; database log mode Archive Mode Automatic archival Enabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 1 Next log sequence to archive 2 Current log sequence 2 above Archive destinatio For the specific location defined by n, you can view the value of db_recovery_file_dest in the $ ORACLE_HOME/dbs/spfile <dbname>. ora file.
4. ONLINE backup: ONLINE backup is a hot backup method. It refers to the process of backing up all data files and individual data files in the tablespace when the tablespace is ONLINE. The advantage of using online backup is that it does not affect all access operations on the table space. However, the disadvantage of online backup may be that it produces more redo log files and archive log files. The following are the specific steps for online backup: <1> Log On As a dba or privileged user to determine the data files contained in the tablespace. You can query the data dictionary DBA_DATA_FILES to obtain the correspondence between the data file and the tablespace:
SQL & gt; select file_name from dba_data_files where tablespace_name = 'users'; FILE_NAME alias/u02/oradata/db01/users01.dbf <2> set the tablespace to the backup mode, before copying a tablespace data file, you must set the Tablespace to the backup mode: SQL & gt; alter tablespace users begin backup; Tablespace altered. <3> copy the users data file to the backup directory: [oracle @ server1 bak] $ cp/u02/oradata/db01/users01.dbf/bak <4> after copying the table space, you do not need to set it to the backup mode. Therefore, you can return it to the normal mode: SQL & gt; alter tablespace users end backup; Tablespace altered.
5. offline backup: offline backup is also a hot backup method. It refers to the process of backing up all data files and individual data files in the tablespace when the tablespace is offline. It produces a small number of redo log files. Its disadvantage is that the tablespace backed up when the user is backing up offline will not be accessible, because the SYSTEM tablespace and the in-use UNDO tablespace cannot be taken offline, offline backup is not applicable to SYSTEM tablespace and the in-use UNDO tablespace. <1> log on with a DBA user or a privileged user to determine the data files contained in the tablespace. This is the first step for online backup:
SQL & gt; select file_name from dba_data_files where tablespace_name = 'users'; FILE_NAME empty/u02/oradata/db01/users01.dbf <2> set the tablespace to offline, after the tablespace is set to OFFLINE, you cannot access any objects in the tablespace. Therefore, you can ensure that the data files in the tablespace of OFFLINE do not change. SQL & gt; alter tablespace users offline; Tablespace altered. SQL & gt; select tablespace_name, online_status from dba_data_files; TABLESPACE_NAME ONLINE _ ------------------------------ ------- USERS OFFLINE SYSAUX ONLINE UNDOTBS1 ONLINE SYSTEM <3> copy users data files to the backup directory: [oracle @ server1 bak] $ cp/u02/oradata/db01/users01.dbf/bak <4> after copying, place the tablespace online: SQL & gt; alter tablespace users online; tablespace altered. SQL & gt; select tablespace_name, online_status from dba_data_files; TABLESPACE_NAME ONLINE _ ------------------------------ ------- USERS ONLINE SYSAUX ONLINE UNDOTBS1 ONLINE SYSTEM

 

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.