在OracleDatabase12.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
成都创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于做网站、成都网站设计、夷陵网络推广、微信小程序定制开发、夷陵网络营销、夷陵企业策划、夷陵品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联公司为所有大学生创业者提供夷陵建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com
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 ch2 device type disk; allocate channel ch3 device type disk; allocate channel ch4 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 ch2; release channel ch3; release channel ch4; }
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、重新启动并备份数据库
文章标题:在OracleDatabase12.1中异机迁移恢复数据库【实战】
标题路径:http://pwwzsj.com/article/jjceis.html