在Oracle Database 12.1 中异机迁移恢复数据库【实战】

平台环境:
源OS:Oracle Linux 7.3
源DB:Oracle Database 12.1.0.2

目标OS:Oracle Linux 7.3
目标DB:Oracle Database 12.1.0.2

一、准备工作
1、查询当前SCN

col current_scn form 99999999999999
SQL> select current_scn from v$database;
    CURRENT_SCN
---------------
  5965538762695

2、显示当前DBID和DBName

SQL> select dbid,name from v$database;
      DBID NAME
 ---------- ---------
  357998902 PROD

3、对当前重做日志进行归档

ALTER SYSTEM ARCHIVE LOG CURRENT;

注:ALTER SYSTEM ARCHIVE LOG CURRENT; 可以保证数据的一致性,而Alter system switch logfile;不能保证数据一致性。

4、准备备份数据

(1)0级备份,1级增量备份,备份时产生的FRA文件
(2)备份ARCHIVELOG 文件
(3)备份参数文件,命令:backup spfile format '/backup/rman_backup/spfile%d_%s_%p_%u.%'

mkdir -p /mnt/data/backup/PBF/archive

注:(1)的文件传输到/mnt/data/backup/PBF
(2)的文件传输到/mnt/data/backup/PBF/archive

二、异机恢复步骤
1、创建密码文件

orapwd file=/mnt/data/PBF/db/12.1.0/dbs/orapwPROD password=oracle entrie=5 format=12

2、准备环境和initPROD.ora

export ORACLE_SID=PROD
echo $ORACLE_SID
vi initPROD.ora
db_name = PROD

3、将数据库启动到nomount状态

sqlplus / as sysdba
startup nomount pfile=/mnt/data/PBF/db/12.1.0/dbs/initPROD.ora;
or
startup nomount;

4、恢复参数文件并修改参数文件

rman target /
restore spfile to pfile '/mnt/data/PBF/db/12.1.0/dbs/initPROD2.ora' from '/mnt/data/backup/PBF/spfilePROD_2402_1_b2stkm1i';

(1)创建路径:

mkdir -p /mnt/data/PBF/db/archive
mkdir -p /mnt/data/PBF/db/db_recovery_dest

(2)修改pfile中的以下参数:

control_files
diagnostic_dest
db_recovery_file_dest

(3)重新启动

shutdown abort;
startup nomount;

5、恢复控制文件,修改数据库到mount状态,并交叉检查备份集

rman target /
restore controlfile from '/mnt/data/backup/PBF/cntrl_20180312.ctl';
alter database mount;
crosscheck backupset;

6、注册备份集文件和FRA中的文件,交叉检查备份集,并删除过期的备份集

catalog start with '/mnt/data/backup/PBF/';
crosscheck backupset;
delete noprompt expired backupset;

7、注册archivelog

CATALOG archivelog '/mnt/data/backup/PBF/archive/1_2213_946160568.dbf','/mnt/data/backup/PBF/archive/1_2214_946160568.dbf','/mnt/data/backup/PBF/archive/1_2215_946160568.dbf','/mnt/data/backup/PBF/archive/1_2216_946160568.dbf','/mnt/data/backup/PBF/archive/1_2217_946160568.dbf','/mnt/data/backup/PBF/archive/1_2218_946160568.dbf','/mnt/data/backup/PBF/archive/1_2219_946160568.dbf','/mnt/data/backup/PBF/archive/1_2220_946160568.dbf','/mnt/data/backup/PBF/archive/1_2221_946160568.dbf','/mnt/data/backup/PBF/archive/1_2222_946160568.dbf';

8、由于路径不一样,使用以下语句批量生成

select 'set newname for datafile '|| file_id || ' to ''/mnt/data/PBF/db/proddata/' ||
        substr(name,
               instr(name,'/', -1) + 1) || ''';'
   from v$datafile
  order by file#;

9、在rman中执行以下脚本

run
{
allocate channel ch1 device type disk;
allocate channel ch2 device type disk;
allocate channel ch3 device type disk;
set newname for datafile 1 to '/mnt/data/PBF/db/proddata/system01.dbf';
set newname for datafile 2 to '/mnt/data/PBF/db/proddata/system02.dbf';
set newname for datafile 3 to '/mnt/data/PBF/db/proddata/system03.dbf';
set newname for datafile 4 to '/mnt/data/PBF/db/proddata/system04.dbf';
set newname for datafile 5 to '/mnt/data/PBF/db/proddata/system05.dbf';
set newname for datafile 6 to '/mnt/data/PBF/db/proddata/ctxd01.dbf';
set newname for datafile 7 to '/mnt/data/PBF/db/proddata/owad01.dbf';
set newname for datafile 8 to '/mnt/data/PBF/db/proddata/a_queue02.dbf';
set newname for datafile 9 to '/mnt/data/PBF/db/proddata/odm.dbf';
set newname for datafile 10 to '/mnt/data/PBF/db/proddata/olap.dbf';
set newname for datafile 11 to '/mnt/data/PBF/db/proddata/sysaux01.dbf';
set newname for datafile 12 to '/mnt/data/PBF/db/proddata/apps_ts_tools01.dbf';
set newname for datafile 13 to '/mnt/data/PBF/db/proddata/system12.dbf';
set newname for datafile 14 to '/mnt/data/PBF/db/proddata/a_txn_data04.dbf';
set newname for datafile 15 to '/mnt/data/PBF/db/proddata/a_txn_ind06.dbf';
set newname for datafile 16 to '/mnt/data/PBF/db/proddata/a_ref03.dbf';
set newname for datafile 17 to '/mnt/data/PBF/db/proddata/a_int02.dbf';
set newname for datafile 18 to '/mnt/data/PBF/db/proddata/sysaux02.dbf';
set newname for datafile 19 to '/mnt/data/PBF/db/proddata/system13.dbf';
set newname for datafile 20 to '/mnt/data/PBF/db/proddata/system14.dbf';
set newname for datafile 21 to '/mnt/data/PBF/db/proddata/system15.dbf';
set newname for datafile 22 to '/mnt/data/PBF/db/proddata/system16.dbf';
set newname for datafile 23 to '/mnt/data/PBF/db/proddata/system17.dbf';
set newname for datafile 24 to '/mnt/data/PBF/db/proddata/system18.dbf';
set newname for datafile 25 to '/mnt/data/PBF/db/proddata/system19.dbf';
set newname for datafile 26 to '/mnt/data/PBF/db/proddata/system20.dbf';
set newname for datafile 27 to '/mnt/data/PBF/db/proddata/system21.dbf';
set newname for datafile 28 to '/mnt/data/PBF/db/proddata/system22.dbf';
set newname for datafile 29 to '/mnt/data/PBF/db/proddata/system23.dbf';
set newname for datafile 30 to '/mnt/data/PBF/db/proddata/system24.dbf';
set newname for datafile 31 to '/mnt/data/PBF/db/proddata/system25.dbf';
set newname for datafile 32 to '/mnt/data/PBF/db/proddata/a_ref04.dbf';
set newname for datafile 33 to '/mnt/data/PBF/db/proddata/a_ref05.dbf';
set newname for datafile 34 to '/mnt/data/PBF/db/proddata/a_ref06.dbf';
set newname for datafile 35 to '/mnt/data/PBF/db/proddata/undo02.dbf';
set newname for datafile 36 to '/mnt/data/PBF/db/proddata/cux_data01.dbf';
set newname for datafile 37 to '/mnt/data/PBF/db/proddata/cux_ind01.dbf';
set newname for datafile 38 to '/mnt/data/PBF/db/proddata/undo03.dbf';
set newname for datafile 39 to '/mnt/data/PBF/db/proddata/undo04.dbf';
set newname for datafile 40 to '/mnt/data/PBF/db/proddata/undo05.dbf';
set newname for datafile 41 to '/mnt/data/PBF/db/proddata/a_media02.dbf';
set newname for datafile 42 to '/mnt/data/PBF/db/proddata/a_media03.dbf';
set newname for datafile 43 to '/mnt/data/PBF/db/proddata/a_media04.dbf';
set newname for datafile 44 to '/mnt/data/PBF/db/proddata/sysaux03.dbf';
set newname for datafile 45 to '/mnt/data/PBF/db/proddata/a_media05.dbf';
set newname for datafile 46 to '/mnt/data/PBF/db/proddata/a_txn_ind07.dbf';
set newname for datafile 47 to '/mnt/data/PBF/db/proddata/a_txn_ind08.dbf';
set newname for datafile 48 to '/mnt/data/PBF/db/proddata/a_txn_data05.dbf';
set newname for datafile 49 to '/mnt/data/PBF/db/proddata/a_txn_data06.dbf';
set newname for datafile 50 to '/mnt/data/PBF/db/proddata/a_queue03.dbf';
set newname for datafile 51 to '/mnt/data/PBF/db/proddata/ctxd02';
set newname for datafile 52 to '/mnt/data/PBF/db/proddata/a_media06.dbf';
set newname for datafile 53 to '/mnt/data/PBF/db/proddata/a_media07.dbf';
set newname for datafile 54 to '/mnt/data/PBF/db/proddata/sysaux04.dbf';
set newname for datafile 55 to '/mnt/data/PBF/db/proddata/a_media08.dbf';
set newname for datafile 56 to '/mnt/data/PBF/db/proddata/a_media09.dbf';
set newname for datafile 57 to '/mnt/data/PBF/db/proddata/sysaux05.dbf';
set newname for datafile 58 to '/mnt/data/PBF/db/proddata/a_txn_ind09.dbf';
set newname for datafile 59 to '/mnt/data/PBF/db/proddata/a_txn_data07.dbf';
set newname for datafile 60 to '/mnt/data/PBF/db/proddata/a_media10.dbf';
set newname for datafile 61 to '/mnt/data/PBF/db/proddata/a_media11.dbf';
set newname for datafile 62 to '/mnt/data/PBF/db/proddata/a_media12.dbf';
set newname for datafile 63 to '/mnt/data/PBF/db/proddata/a_media13.dbf';
set newname for datafile 64 to '/mnt/data/PBF/db/proddata/a_media14.dbf';
set newname for datafile 65 to '/mnt/data/PBF/db/proddata/a_media15.dbf';
set newname for datafile 66 to '/mnt/data/PBF/db/proddata/a_media16.dbf';
set newname for datafile 67 to '/mnt/data/PBF/db/proddata/a_media17.dbf';
set newname for datafile 68 to '/mnt/data/PBF/db/proddata/a_media18.dbf';
set newname for datafile 69 to '/mnt/data/PBF/db/proddata/a_queue04.dbf';
set newname for datafile 70 to '/mnt/data/PBF/db/proddata/a_media19.dbf';
set newname for datafile 71 to '/mnt/data/PBF/db/proddata/a_media20.dbf';
set newname for datafile 72 to '/mnt/data/PBF/db/proddata/a_media21.dbf';
set newname for datafile 288 to '/mnt/data/PBF/db/proddata/system10.dbf';
set newname for datafile 295 to '/mnt/data/PBF/db/proddata/system06.dbf';
set newname for datafile 314 to '/mnt/data/PBF/db/proddata/portal01.dbf';
set newname for datafile 351 to '/mnt/data/PBF/db/proddata/system07.dbf';
set newname for datafile 352 to '/mnt/data/PBF/db/proddata/system09.dbf';
set newname for datafile 353 to '/mnt/data/PBF/db/proddata/system08.dbf';
set newname for datafile 354 to '/mnt/data/PBF/db/proddata/system11.dbf';
set newname for datafile 379 to '/mnt/data/PBF/db/proddata/undo01.dbf';
set newname for datafile 392 to '/mnt/data/PBF/db/proddata/a_txn_data01.dbf';
set newname for datafile 393 to '/mnt/data/PBF/db/proddata/a_txn_ind01.dbf';
set newname for datafile 394 to '/mnt/data/PBF/db/proddata/a_ref01.dbf';
set newname for datafile 395 to '/mnt/data/PBF/db/proddata/a_int01.dbf';
set newname for datafile 396 to '/mnt/data/PBF/db/proddata/a_summ01.dbf';
set newname for datafile 397 to '/mnt/data/PBF/db/proddata/a_nolog01.dbf';
set newname for datafile 398 to '/mnt/data/PBF/db/proddata/a_archive01.dbf';
set newname for datafile 399 to '/mnt/data/PBF/db/proddata/a_queue01.dbf';
set newname for datafile 400 to '/mnt/data/PBF/db/proddata/a_media01.dbf';
set newname for datafile 401 to '/mnt/data/PBF/db/proddata/a_txn_data02.dbf';
set newname for datafile 402 to '/mnt/data/PBF/db/proddata/a_txn_data03.dbf';
set newname for datafile 403 to '/mnt/data/PBF/db/proddata/a_txn_ind02.dbf';
set newname for datafile 404 to '/mnt/data/PBF/db/proddata/a_txn_ind03.dbf';
set newname for datafile 405 to '/mnt/data/PBF/db/proddata/a_txn_ind04.dbf';
set newname for datafile 406 to '/mnt/data/PBF/db/proddata/a_txn_ind05.dbf';
set newname for datafile 407 to '/mnt/data/PBF/db/proddata/a_ref02.dbf';
restore database;
restore archivelog from logseq 2213 until logseq 2222;
switch datafile all;
recover database until scn 5965538762695;
release channel ch1;
release channel ch2;
release channel ch3;
}

10、联机在线日志的处理
(1)生成处理脚本查询:

set linesize 180 pagesize 100
select 'alter database rename file '''||member||''' to ''/mnt/data/PBF/db/proddata/redoXXX.log'';' from v\$logfile;

(2)处理脚本:

alter database rename file '/data/prod/proddata/log02a.dbf' to '/mnt/data/PBF/db/proddata/redo02a.log';
alter database rename file '/data/prod/proddata/log02b.dbf' to '/mnt/data/PBF/db/proddata/redo02b.log';
alter database rename file '/data/prod/proddata/log01a.dbf' to '/mnt/data/PBF/db/proddata/redo01a.log';
alter database rename file '/data/prod/proddata/log01b.dbf' to '/mnt/data/PBF/db/proddata/redo01b.log';
alter database rename file '/data/prod/proddata/log03a.dbf' to '/mnt/data/PBF/db/proddata/redo03a.log';
alter database rename file '/data/prod/proddata/log04a.dbf' to '/mnt/data/PBF/db/proddata/redo04a.log';
alter database rename file '/data/prod/proddata/log05a.dbf' to '/mnt/data/PBF/db/proddata/redo05a.log';
alter database rename file '/data/prod/proddata/log03b.dbf' to '/mnt/data/PBF/db/proddata/redo03b.log';
alter database rename file '/data/prod/proddata/log04b.dbf' to '/mnt/data/PBF/db/proddata/redo04b.log';
alter database rename file '/data/prod/proddata/log05b.dbf' to '/mnt/data/PBF/db/proddata/redo05b.log';

11、临时表空间文件的处理

(1)生成处理脚本查询:

set linesize 180 pagesize 100
select 'alter database rename file '''||name||''' to ''/mnt/data/PBF/db/proddata/tempXXX.dbf'';' from v$tempfile;

(2)处理脚本:

alter database rename file '/data/prod/proddata/temp11.dbf' to '/mnt/data/PBF/db/proddata/temp11.dbf';
alter database rename file '/data/prod/proddata/temp21.dbf' to '/mnt/data/PBF/db/proddata/temp21.dbf';
alter database rename file '/data/prod/proddata/temp12.dbf' to '/mnt/data/PBF/db/proddata/temp12.dbf';
alter database rename file '/data/prod/proddata/temp22.dbf' to '/mnt/data/PBF/db/proddata/temp22.dbf';
alter database rename file '/data/prod/proddata/temp32.dbf' to '/mnt/data/PBF/db/proddata/temp32.dbf';
alter database rename file '/data/prod/proddata/temp42.dbf' to '/mnt/data/PBF/db/proddata/temp42.dbf';
alter database rename file '/data/prod/proddata/temp13.dbf' to '/mnt/data/PBF/db/proddata/temp13.dbf';
alter database rename file '/data/prod/proddata/temp33.dbf' to '/mnt/data/PBF/db/proddata/temp33.dbf';
alter database rename file '/data/prod/proddata/temp43.dbf' to '/mnt/data/PBF/db/proddata/temp43.dbf';
alter database rename file '/data/prod/proddata/temp31.dbf' to '/mnt/data/PBF/db/proddata/temp31.dbf';
alter database rename file '/data/prod/proddata/temp41.dbf' to '/mnt/data/PBF/db/proddata/temp41.dbf';

12、处理 redolog重建时出现的 ORA-00312错误

SQL> alter database open resetlogs;
alter database open resetlogs *
ERROR at line 1:
ORA-00392: log 4 of thread 1 is being cleared, operation not allowed
ORA-00312: online log 4 thread 1: '/mnt/data/PBF/db/proddata/redo04a.log'
ORA-00312: online log 4 thread 1: '/mnt/data/PBF/db/proddata/redo04b.log'

(1)查询redolog文件及其状态

col group# form 99
 col bytes form 99999999999
 col status form a20
select group#,bytes/1024/1024||'M',status from v$log;

(2)修改redolog文件的状态

 alter database clear logfile group 1;
 alter database clear logfile group 2;
 alter database clear logfile group 3;
 alter database clear logfile group 4;
 alter database clear logfile group 5;

(3)再次确认其状态

 select group#,bytes/1024/1024||'M',status from v$log;

13、使用resetlogs方式打开

SQL> alter database open resetlogs;

14、创建新的spfile文件

create spfile from pfile;

15、重新启动并备份数据库

原文地址:http://blog.51cto.com/peenboo/2087290

时间: 2024-08-02 16:16:27

在Oracle Database 12.1 中异机迁移恢复数据库【实战】的相关文章

Oracle Database 12.2新特性详解

在2015年旧金山的Oracle OpenWorld大会上,Oracle发布了Database 12.2的Beta版本,虽然Beta版本只对部分用户开放,但是大会上已经公布了12.2的很多重要的新特性,云和恩墨是Oracle的Beta用户,已经开始测试这一产品.在刚刚结束的"Oracle技术嘉年华"大会上,更详细的主题分享披露了更多内容.在这篇文章中,我将和大家一一来细数Oracle Database 12.2的新特性. Oracle Sharding的实现 简单来说,Oracle的S

RMAN数据库异机迁移步骤

--RMAN数据库异机迁移步骤----------------------------2013/09/28 测试环境:AIX+ora11g   一. source数据库准备.   1.获取数据文件编号和路径   SQL> select file_id,file_name from dba_data_files order by file_id;      FILE_ID FILE_NAME ---------- ------------------------------------------

rman 冷备份异机迁移

rman 作为 oracle 推荐的备份.恢复方式,我们常使用它来进行异机迁移数据库. 网上的攻略都是 rman 的热备份异机迁移,相比冷备份的异机迁移需要多备份归档(未归档)日志文件.联机日志文件,操作步骤较为复杂. 如果是可以停机的数据库,更推荐使用 mount 方式下的冷备份来做异机迁移. 写了一个迁移文件,以备后用. Part1 Env { 'first database':{ 'os':'suse11' 'oracle_version':'11gr2' } 'second databa

Oracle 11G RMAN 单实例异机恢复

数据备份当然是为数据恢复准备,新环境的oracle一直在进行备份,但都没有测试验证备份的有效性,所以本次测试的重要性不言而喻了!以下为WIN平台下RMAN异机恢复实例. 源库 目标库 操作系统 WIN SVR 2008 R2 WIN SVR 2008 R2 主机名 Ora ORATEST IP 192.168.18.20 192.168.18.25 数据库版本 11.2.0.1.0 11.2.0.1.0 存储方式 单实例 单实例 ORACLE_HOME D:\app\Administrator\

实战:Oracle10.2.0.4异机迁移并升级到Oracle 11.2.0.4

环境: 源库:192.168.8.132   oracle10.2.0.4 目标库:192.168.8.133 oracle11.2.0.4 OS:linux 5.4-64位 将原10G的库迁移到新主机133上面,数据库版本同时升级为11.2.0.4 主要步骤: 一.环境检查(源库) 1.将11g中的utlu112i.sql,cp到源主机上,进行升级检查: 2.通过dbupgdiag.sql脚本来检查源库的一致性,如果有无效对象,@utlrp.sql可以对其进行重编译 3.对源库进行备份 二.迁

Oracle之使用rman进行异机恢复测试记录

本次测试目的是从生产数据库导出rman备份然后在测试数据库恢复 1,拷贝备份至相应目录 2,进入rman rman target \ 3,关闭数据库 shutdown 4,以nomount模式启动数据库 startup nomount 5,恢复控制文件 restore controlfile from ' /home/oracle/rman_backup/cf_c-1383295282-20171102-00'; 6,挂载数据库 alter database mount; 7,设置catalog

oracle异机不完全恢复数据库

准备参数文件: [[email protected] ~]$ cat pfileCWERPDB.ora CWERPDB.__db_cache_size=8959033344 CWERPDB.__java_pool_size=67108864 CWERPDB.__large_pool_size=100663296 CWERPDB.__oracle_base='/home/u01/oracle'#ORACLE_BASE set from environment CWERPDB.__pga_aggre

Oracle database datafile header中记录的datafile的大小

本文的环境:Oracle Databae 12.1.0.2, rhel5.9 x86-64bit [[email protected] orcl]$ pwd /u01/app/oracle/oradata/orcl [[email protected] orcl]$ ls -lrt total 2386544 drwxr-x--- 2 oracle oinstall 4096 Dec 26 2014 pdbseed drwxr-x--- 2 oracle oinstall 4096 Dec 26

ASM磁盘组异机迁移

环境: Source: OS:redhat 6.3 DB:Oralce RAC 11.2.4.0 destination: OS:redhat 6.3 DB:Oralce RAC 11.2.4.0 背景:客户的PC机上面有两个实例,压力太大,需要迁移出一个实例.数据量TB级别,因为同平台,同版本,外挂存储.所以这里采用直接迁移asm磁盘组 操作前需要注意的: 1.Voting Disk是单独的盘,不包含需要迁移的数据 话不多,这里模拟出来分享给大家(PS:我的原库和目标库的主机名是一样的,第三步