如何使用 RMAN 从完整恢复备份数据集创建测试数据库?

poj*_*guy 5 oracle rman oracle-12c

对于 DBA 角色是第三或第七位并且很少接触 Oracle 的人来说,我该如何使用 RMAN 从完整恢复备份数据集创建测试数据库?

在问题的结尾我一直在抱怨......

设想:

我有一个完整的生产数据库 RMAN 备份集,作为闪回恢复目录的副本,我想从中构建一个测试数据库。

我已经开始从这篇文章中了解我需要做的事情:Oracle 11 rman db restore file corruption

我没有得到的是他的示例脚本中的一些“字母汤”来自哪里。

示例脚本(带注释):

rman target /
set DBID ...    // Where does this come from?  The existind DB I plan to overlay, or some magic spot in the RMAN backup set?
startup nomount
RESTORE CONTROLFILE FROM 'file destination' // is this my flash recovery directory?
shutdown;
startup mount;

// Is it right to assume that this is the directory containing the backup?
// Or should I list every single backup file from the flash recovery area (ugh!)?
catalog backuppiece 'C:/BKUP/AL_2851492942_20151016_893271615_PGQJSFHV_1_1';

rman:crosscheck backup; Run{
SET UNTIL SEQUENCE 50511;    // Where did this number come from?  Is it important?  Can I ignore this line since I have a complete recovery set?
RESTORE DATABASE;
SWITCH DATAFILE ALL;
RECOVER DATABASE; 
}


sqlplus sys/sys as sysdba

shutdown immediate; startup mount;
alter database noarchivelog; // I see this is considered a bad practice elsewhere??

ALTER DATABASE OPEN;
ALTER TABLESPACE mytempspace // what's this line about?  I just want to take a clone of the DB that was backed up elsewhere
ADD TEMPFILE 'c:\oracle............dbf' SIZE 1G REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
Run Code Online (Sandbox Code Playgroud)

抱怨:

我知道这是另一个菜鸟问题,你们中的一些有经验的 Oracle DBA 会翻白眼并思考“RTFM”。不幸的是,SQL 服务器的易于管理正在改变行业的期望,任何会使用鼠标的人都有望成为即时 DBA。这适用于 SQLServer,但不适用于 Oracle。

在 SQL Server 中,这是一个简单的任务,归结为选择源备份集,选择目标数据库,单击“从备份替换数据库”,单击“执行”,然后去喝咖啡。

在带有 rman 的 Oracle 中,它看起来也应该是一项简单的任务,但我发现的所有文档似乎都假设 oracle DBA 角色由一名全职的 oracle 专家担任,他只需要在正确的方向上进行推动。虽然 Tom Kite 真的很棒,但他在这个确切问题上的页面花费了大量时间喋喋不休地谈论可移动空间等,并且由于读者知识深度的假设而很快变得难以理解。

小智 3

首先要检查的是Oracle官方文档。例如http://docs.oracle.com/cd/E36909_01/backup.1111/e10642/rcmdupdb.htm#autoId0 取决于您的数据库版本(10g、11g、12c...)。只需搜索文档以查找重复的数据库。我不会解释你的脚本中的所有问题,因为它只会让你更加困惑。

根据产品数据库的大小,您可以使用数据泵导出和导入,或者可传输表空间,或者像您尝试过的 RMAN 一样。你的 rman 命令应该是这样的

-- scripts for restore using RMAN, 
-- This script is usable when the oracle versions are the same, 
-- or a direct upgrade is supported
--
-- prep database for rman import
rman target /
shutdown immediate
startup nomount
exit


-- duplicate the database
rman auxiliary /
duplicate database to newdb
  backup location 'E:\Backup\oracle\flash_recovery_area\olddb\BACKUPSET\2016_07_29' nofilenamecheck 
  DB_FILE_NAME_CONVERT ('E:\app\oracle\oradata\olddb','E:\Oracle\oradata\newdb')
  LOGFILE
    'E:\Oracle\oradata\newdb\redo01.log' SIZE 2G,
    'E:\Oracle\oradata\newdb\redo02.log' SIZE 2G,
    'E:\Oracle\oradata\newdb\redo03.log' SIZE 2G;

duplicate database to testdb spfile backup location 'backup_path' nofilenamecheck;
Run Code Online (Sandbox Code Playgroud)

当数据库版本不同时,使用expdp/impdp:

-- Alternate procedure using using expdp / impdp
--
-- Export on source database
sqlplus: create or replace directory data_pump_directory as 'f:\dp';

cmd: expdp user/password@olddb schemas=SchemaToMigrate directory=data_pump_directory dumpfile=dbname.dmp logfile=expdp_dbname.log

-- generate script for generating user from old database
-- see http://www.oracle-scripts.net/generate-user-ddl/
--
-- copy output files from source system to destination system
--
-- Prep destination database for the import
-- use script generated above to create user/schema on destination database
sqlplus: create or replace directory data_pump_directory as 'f:\dp';

-- From bitter experience, this will not necessarily work with the user/password@newdb 
-- on the command line.  
-- If impdp chokes with ORA-39087:
-- 1. Confirm database is open (alter databaase open)
-- 2. Confirm the directory reference is created in the database
-- 3. Confirm the system and schema users are granted read and write on the directory reference
-- 4. Confirm the oracle service (OS) user has authority on the OS directory
-- 5. then try not supplying credentials until impdp asks for them (yeah,  a possible bug somewhere)
cmd: impdp user/password@newdb schemas=SchemaToMigrate directory=data_pump_directory dumpfile=dbname.dmp logfile=impdp_dbname.log table_exists_action=replace  remap_tablespace=oldts1:newts1,oldts2:newts2
Run Code Online (Sandbox Code Playgroud)

这个脚本可以有多种写法,具体取决于你是否要恢复到特定的日期和时间、特定的SCN、测试数据库是否具有相同的结构(数据和其他文件的相同路径)是否相同、操作系统是否相同,您是否需要更改一些初始化参数等。