Backup and recovery (4)-RMAN uses the recovery catalog to save the archive database

(1) Overview of recovery catalog

The RMAN archive database is used to store information required for database backup, repair, and recovery. This information can be saved in the control file of the backup database, or it can be saved separately in the recovery directory of an independent recovery catalog database. The difference between the two methods is as follows:

(1) Save the backup information in the control file. If the backup information is saved in the control file, then the control file will include non-reusable records and reusable records. What is not reusable is record data files, online log files and other infrequently changing, critical information ; Repeatable is the continuously new information generated during the operation of the database, such as: historical information of redo log files, archived log file information, backup information, etc. Because the reusable space is limited and work is carried out in a cyclical manner, the backup information that can be saved is also limited.

(2) Save the backup information in the recovery directory. When RMAN is used to backup and restore the database, RMAN obtains the required information directly from the recovery catalog instead of obtaining information from the control file. A recovery catalog can be used by multiple target databases, just register the target database to the recovery catalog. The recovery catalog mainly saves:

  • Information about target database data files and redo log files
  • Mirror copy information of target database
  • The relationship between the target database table space and data files
  • Store user-created RMAN scripts, which can be reused
  • Permanent RMAN predefined parameter configuration information

This article will use the recovery catalog for backup and recovery tests.


(2) Test environment information

IP address Database instance name Remarks
192.168.10.11 testdb1 Database 1 to be backed up, also known as the target database
192.168.10.12 testdb2 Database to be backed up 2, also known as the target database
192.168.10.51 catalogdb catalog database

              
(3) Configure the recovery catalog for the database

(3.1) Create a table space in the recovery catalog database (192.168.10.51:catalogdb) for storing RMAN backup data

create tablespace recovery_catalog datafile '/u01/app/oracle/oradata/catalogdb/catalog.dbf' size 1g;

(3.2) Create a user in the recovery catalog database

The same user can be used for multiple target databases, or a user can be created separately for each target database. Here, a user is created separately for each target database.

- used to do sourcedb recovery catalog user 
the Create  the User rman_testdb1 IDENTIFIED by "rman_testdb1" default TABLESPACE recovery_catalog the Temporary TABLESPACE the TEMP ;
  Grant the RECOVERY_CATALOG_OWNER, Connect, Resource to rman_testdb1; 

- used to do targetdb recovery catalog user 
the Create  the User rman_testdb2 IDENTIFIED by " rman_testdb2 " default tablespace recovery_catalog temporary tablespace temp ;
  grant recovery_catalog_owner, connect, resource to rman_testdb2;


(3.3) Configure the connection string of each instance

Configure the connection string tnsnames.ora for each server. The target database node needs to configure the tns of the catalog database. The catalog database needs to configure the tns of all target databases.
(3.3.1) Add the connection string of the catalogdb database to the testdb1 node

[oracle@source-node admin]$ cat tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

CATALOGDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.51)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = catalogdb)
    )
  )


(3.3.2) Add the connection string of the catalogdb database to the testdb2 node

CATALOGDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.51)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = catalogdb)
    )
   )

(3.3.3)在catalogdb节点添加testdb1和testdb2数据库的连接字符串

testdb1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = testdb1)
    )
  )

testdb2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.12)(PORT = 1521))
    )
    (CONNECT_DATA =
       (SERVICE_NAME = testdb2)
     )
   )


(3.4)启动RMAN,创建恢复目录
在catalogdb数据库节点启动RMAN,创建恢复目录

(3.4.1)为testdb1创建恢复目录

## testdb1
[oracle@primarynode admin]$ rman 

RMAN> connect catalog rman_testdb1/rman_testdb1
connected to recovery catalog database

RMAN> create catalog tablespace recovery_catalog;
 recovery catalog created


(3.4.2)为testdb2创建恢复目录

## testdb2
[oracle@primarynode admin]$ rman

RMAN> connect catalog rman_testdb2/rman_testdb2
connected to recovery catalog database

RMAN> create catalog tablespace recovery_catalog;
 recovery catalog created


(3.5)注册数据库
(3.5.1)将testdb1注册到恢复目录中

[oracle@primarynode admin]$ rman


 RMAN> connect target sys/Oracle123@testdb1
 connected to target database: TESTDB1 (DBID=789833349)

RMAN> connect catalog rman_testdb1/rman_testdb1
 connected to recovery catalog database

RMAN> register database;
 database registered in recovery catalog
 starting full resync of recovery catalog
 full resync complete

RMAN> exit


(3.5.2)将testdb2注册到恢复目录中

[oracle@primarynode admin]$ rman

RMAN> connect target sys/Oracle123@testdb2
 connected to target database: TESTDB2 (DBID=1359425552)

RMAN> connect catalog rman_testdb2/rman_testdb2
 connected to recovery catalog database

RMAN> register database;
 database registered in recovery catalog
 starting full resync of recovery catalog
 full resync complete


(四)备份与恢复测试
(4.1)创建测试数据

在数据库testdb1中的用户lijiaman下面创建表test01,并插入测试数据

create user lijiaman identified by "lijiaman";
 grant dba,connect to lijiaman;

create table lijiaman.test01 
 (
   id     number primary key,
   name   varchar2(30)
 );

insert into lijiaman.test01 values(1,'a');
 commit;

(4.2)将test01数据库备份到/rman_backup目录下面,需要主义的是,备份只能放在目标数据库服务器的本地

# 创建备份路径
[root@primarynode ~]# mkdir /rman_backup
[root@primarynode ~]# chown -R oracle:oinstall /rman_backup/
# 开始备份
rman target sys/Oracle123@testdb1 catalog rman_testdb1/rman_testdb1

run{            
 configure controlfile autobackup on;
 configure controlfile autobackup format for device type disk to '/rman_backup/controlfile_%F.bak';
 allocate channel c1 type disk;
 backup full tag 'dbfull' format '/rman_backup/full_%u_%s_%p' database;
 sql 'alter system archive log current';
 backup archivelog all format '/rman_backup/arch_%u_%s_%p';
 backup spfile format '/rman_backup/spfile_%d_%U';
 delete noprompt expired backup;
 delete noprompt obsolete;
 release channel c1;
}

(4.3)模拟误操作

--查看误操作之前的时间

select sysdate from dual;
sysdate
-------------
2020/4/14 20:48:55 


--执行trucnate操作:
truncate table lijiaman.test01;

(4.4)执行恢复
将数据库恢复到truncate之前,这里恢复到2020/4/14 20:48:55
(4.4.1)将testdb1设置为mount状态

[oracle@source-node ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Apr 14 20:54:18 2020

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


 Connected to:
 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
 With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate
 Database closed.
 Database dismounted.
 ORACLE instance shut down.
 SQL> startup mount
ORACLE instance started.

Total System Global Area  584568832 bytes
 Fixed Size            2255432 bytes
Variable Size          369100216 bytes
Database Buffers      205520896 bytes
Redo Buffers            7692288 bytes
Database mounted.

(4.4.2)在备份服务器catalog上执行恢复操作

rman target sys/Oracle123@testdb1 catalog rman_testdb1/rman_testdb1
RMAN>SQL"ALTER SESSION SET NLS_LANGUAGE=''AMERICAN''";
RMAN>SQL"ALTER SESSION SET NLS_DATE_FORMAT=''YYYY-MM-DD HH24:MI:SS''";
RUN{
SET UNTIL TIME '2020-04-14 20:48:55';
RESTORE DATABASE;
RECOVER DATABASE;
 }


(4.5)因为是不完全恢复,以resetlogs方式打开数据库

SQL> alter database open resetlogs;

Database altered.

(4.6)确认数据已经还原回来

SQL> select * from lijiaman.test01;
    ID NAME
---------- ------------------------------
     1 a


(五)总结

个人觉得,使用恢复目录来保存RMAN信息的优点有:可以长久保存RMAN信息,可以保存RMAN脚本。

与将备份信息保存在控制文件相比,最大的差别是:使用catalog时,执行备份恢复都需要连接到两个数据库,而使用控制文件则只需连接待恢复的数据库。


【完】          

Guess you like

Origin www.cnblogs.com/lijiaman/p/12701390.html