Oracle Database 12.1 中异机迁移恢复数据库(直接拷贝恢复)

时间:2019-12-07
本文章向大家介绍Oracle Database 12.1 中异机迁移恢复数据库(直接拷贝恢复),主要包括Oracle Database 12.1 中异机迁移恢复数据库(直接拷贝恢复)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1.准备 工作

查询当前SCN

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

显示当前DBID和DBName

SQL> select dbid,name from v$database;
      DBID NAME
 ---------- ---------
  35778902 ORCL

对当前重做日志进行归档

ALTER SYSTEM ARCHIVE LOG CURRENT;

准备备份数据

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

2.异机恢复数据

创建密码文件

orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID force=y

准备环境和initPROD.ora

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


*.audit_file_dest='C:\app\Administrator\admin\orcl\adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='C:\app\Administrator\oradata\orcl\control01.ctl','C:\app\Administrator\oradata\orcl\control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.diagnostic_dest='C:\app\Administrator'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.log_archive_dest_1='LOCATION=C:\app\arch'
*.memory_target=1234173952
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'

将数据库启动到nomount状态

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

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

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

修改pfile中的以下参数


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


control_files diagnostic_dest db_recovery_file_dest

重新启动

shutdown abort;
startup nomount;

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

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

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

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

注册archivelog

CATALOG START WITH '归档文件路径'
recover database还原归档文件
或者
归档文件已经还原回来
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';

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

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#;

或者在SQL下执行(生成的脚本在数据库中运行,上面的在rman中运行)
select 'alter database rename file''' || name|| ''' to ''/mnt/data/PBF/db/proddata/' || substr(name,instr(name,'/', -1) + 1) || ''';' from v$datafile order by file#;
--alter database rename file '+DATA1/ORAPUABIS/TEMPFILE/temp.278.981310047' to '/oradata/orapuabis/temp001.dbf';

在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';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;
}

联机在线日志的处理

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

临时表空间文件的处理

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

处理 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'

查询redolog文件及其状态

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

修改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;

使用resetlogs方式打开

SQL> alter database open resetlogs;

create spfile from pfile;

重新启动并备份数据库

原文地址:https://www.cnblogs.com/yrash/p/12002329.html