如何使用RMAN创建测试库(duplicate)

截图是个体力活,把图片弄到文章里又是一通折腾,俺是坚定地纯文字版!

场景: 2台虚拟机,一台有数据库ORCL,另一台只装了数据库软件
要求: 将ORCL 迁移到另一台上,不允许宕机

约定:采用最简单的相同路径设置
生产库: 192.168.0.1
oracle linux 5.8 64 bit
ORACLE_BASE: /u01/app/oracle
ORACLE_HOME: /u01/app/oracle/product/10.2.0/db_1
db_block_size: 8k
已归档
实例 orcl

辅助库: 192.168.0.2
oracle solaris 10 64 bit
ORACLE_BASE: /u01/app/oracle
ORACLE_HOME: /u01/app/oracle/product/10.2.0/db_1
实例 无

0 检查生产库是否归档
SQL> archive log list;

如未归档,执行命令
SQL> shutdown immediate ;
SQL> startup mount ;
SQL> ALTER DATABASE ARCHIVELOG;
SQL> ALTER DATABASE OPEN;


1 在辅助库机器上创建密钥文件
$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle entries=3


2 配置初始化参数文件,直接COPY生产库的参数文件到辅助库机器上
辅助库机器上执行:
$ scp oracle@192.168.0.1:/u01/app/oracle/product/10.2.0/db_1/dbs/spfileorcl.ora /u01/app/oracle/product/10.2.0/db_1/dbs
$ vi /u01/app/oracle/product/10.2.0/db_1/dbs/spfileorcl.ora
orcl.__db_cache_size=176160768
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__shared_pool_size=92274688
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.background_dump_dest='/u01/app/oracle/admin/orcl/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl','/u01/app/oracle/oradata/orcl/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/orcl/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.job_queue_processes=10
*.log_archive_dest_1='location=/u01/app/oracle/archive'
*.log_archive_format='arch_%t_%s_%r.arc'
*.open_cursors=300
*.pga_aggregate_target=92274688
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=278921216
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/orcl/udump'


3 创建相关目录
出现在spfile中的目录都要存在
$ mkdir -p /u01/app/oracle/oradata/orcl
$ mkdir -p /u01/app/oracle/admin/orcl/adump
$ mkdir -p /u01/app/oracle/admin/orcl/bdump
$ mkdir -p /u01/app/oracle/admin/orcl/cdump
$ mkdir -p /u01/app/oracle/admin/orcl/udump
$ mkdir -p /u01/app/oracle/flash_recovery_area
$ mkdir -p /u01/app/oracle/archive


4 启动辅助库到NOMOUNT状态
$ sqlplus sys/oracle as sysdba
SQL> startup nomount;


5 配置监听和网络服务名,并启动监听
在辅助库机器上生成listener.ora,内容来自本机listener.ora中的相关内容
$ vi $ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PL***tProc)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(SID_NAME = orcl)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = caral2)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)

生成辅助库机器上的tnsnames.ora文件,内容如下
$ vi $ORACLE_HOME/network/admin/tnsnames.ora
AUX =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)

EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PL***tProc)
(PRESENTATION = RO)
)
)


启动辅助库机器上的监听
$ lsnrctl start


测试辅助库远程登录
$ sqlplus sys/oracle@aux as sysdba


修改生产机的tnsnames.ora文件,添加内容
$ vi $ORACLE_HOME/network/admin/tnsnames.ora
AUX =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)

生产机上测试远程登录辅助库
$ lsnrctl stop
$ lsnrctl start
$ sqlplus sys/oracle@aux as sysdba


6 在生产机数据库OPEN状态下,备份数据库
为了后期验证,建一个测试表
SQL> CREATE TABLE scott.test AS SELECT * FROM scott.emp;
SQL> UPDATE scott.test
SET SAL =1;
SQL> commit;

$ mkdir -p /u01/data/aux
$ rman target /
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/data/aux/ctl_%F';
RMAN> run {
allocate channel c1 type disk;
backup database format '/u01/data/aux/db_%U';
backup archivelog all delete all input format '/u01/data/aux/arch_%U';
release channel c1;
}


7 将生产库的备份文件拷贝到辅助库
$ mkdir -p /u01/data/aux
$ scp oracle@192.168.0.1:/u01/data/aux/* /u01/data/aux


8 开始duplicate
注意: 执行本步骤前,如果有其他与辅助库的连接,切记断开!否则duplicate的命令会跟我之前一样一直挂在
contents of Memory Script:
{
shutdown clone;
startup clone nomount ;
}
executing Memory Script
那儿摆POSE!害俺傻乎乎地为此折腾了好几遍操作!

在生产机执行下列命令
$ rman target sys/oracle@orcl auxiliary sys/oracle@aux
RMAN> duplicate target database to orcl nofilenamecheck;


9 验证一下
辅助库上执行:
$ sqlplus sys/oracle as sysdba
SQL> SELECT sal FROM scott.test GROUP BY sal;

至此OK!
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值