标签:table 插入 ace smo sele ati iam def ini
(一)恢复目录概述
RMAN档案资料库用于存储数据库备份、修复以及恢复所需的信息。这些信息可以保存在备份数据库的控制文件中,也可以单独保存在一个独立的恢复目录数据库的恢复目录中。两种方式差别如下:
(1)将备份信息保存在控制文件中。如果将备份信息保存在控制文件中,那么控制文件中将包括不可重复使用的记录和可以重复使用的记录,不可重复使用的是记录数据文件、联机日志文件等不经常变化的、关键性的信息;可重复的是数据库运行过程中不断新生成的信息,如:重做日志文件的历史信息、归档日志文件信息、备份信息等。因为可重复使用的空间是有限的,采用循环覆盖的方式进行工作,因此,能够保存的备份信息也有限。
(2)将备份信息保存在恢复目录中。使用RMAN对数据库进行备份恢复时,RMAN直接从恢复目录获取所需信息,而不是从控制文件获取信息。一个恢复目录可以被多个目标数据库使用,只需将目标数据库注册到恢复目录即可。恢复目录主要保存:
本文将使用恢复目录进行备份恢复测试。
(二)测试环境信息
IP地址 | 数据库实例名 | 备注 |
192.168.10.11 | testdb1 | 待备份数据库1,也称目标数据库 |
192.168.10.12 | testdb2 | 待备份数据库2,也称目标数据库 |
192.168.10.51 | catalogdb | catalog数据库 |
(三)为数据库配置恢复目录
(3.1)在恢复目录数据库(192.168.10.51:catalogdb)创建表空间用于存放RMAN备份数据
create tablespace recovery_catalog datafile ‘/u01/app/oracle/oradata/catalogdb/catalog.dbf‘ size 1g;
(3.2)在恢复目录数据库创建用户
多个目标数据库可以使用同一个用户,也可以单独为每个目标数据库创建一个用户,这里为每个目标库单独创建用户。
--用来做sourcedb的恢复目录用户 create user rman_testdb1 identified by "rman_testdb1" default tablespace recovery_catalog temporary tablespace temp; grant recovery_catalog_owner,connect,resource to rman_testdb1; --用来做targetdb的恢复目录用户 create 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)配置各个实例的连接字符串
为各个服务器配置连接字符串tnsnames.ora,目标数据库节点需要配置catalog数据库的tns,catalog数据库需要配置所有目标数据库的tns。
(3.3.1)在testdb1节点添加catalogdb数据库的连接字符串
[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)在testdb2节点添加catalogdb数据库的连接字符串
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时,执行备份恢复都需要连接到两个数据库,而使用控制文件则只需连接待恢复的数据库。
备份与恢复(四)--RMAN使用恢复目录catalog来保存档案资料库
标签:table 插入 ace smo sele ati iam def ini
原文地址:https://www.cnblogs.com/lijiaman/p/12701390.html