您的位置:首页 > 数据库 > Oracle

oracle 11g asm单实例迁移文件系统

2014-05-29 21:38 411 查看
上一次做完ASM单实例的例子以后,今天我想做一个asm单实例迁移文件系统的例子。

环境如下:

10.10.27.16(hostname:shu3) oracle 11.2.0.4.0 ASM单实例 DB

10.10.27.17(hostname:shu4) oracle 11.2.0.4.0 文件系统 DB

迁移思路:利用rman备份集,复制到目标数据源以后,创建相关路径,恢复spfile(修改相关路径),恢复controlfile文件,数据库mount以后,RMAN还原和恢复并修改相关数据文件路径,手工修改online redo文件路径,利用resetlogs的选项启动数据库open,修改temp文件。

步骤一:目标数据库创建相关文件夹

[oracle@shu4 ]$
[oracle@shu4 ]$ cd /u01/oracle/app/oracle/
[oracle@shu4 ]$ mkdir -p admin/PROD/{a,b,c,u}dump  #一些跟踪文件路径
[oracle@shu4 ]$ mkdir -p oradata/PROD #数据文件 online redo 控制文件都放在里面
[oracle@shu4 ]$
[oracle@shu4 ]$ cd /u01/oracle/app/oracle/product/11.2.0/dbs/
[oracle@shu4 ]$ orapwd file=orapwPROD password=oracle entries=30 force=y  #密码文件
[oracle@shu4 ]$ ls
init.ora  orapwPROD
[oracle@shu4 ]$
[oracle@shu4 ]$


步骤二:从备份集取出spfile和controlfile文件

[oracle@shu4 ]$
[oracle@shu4 ]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Thu May 29 20:53:30 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> restore spfile to '/u01/oracle/app/oracle/product/11.2.0/dbs/spfilePROD.ora' from '/u01/backup/suys_spfile_09p9eqo4_1_1_20140528';

Starting restore at 2014-05-29 20:53:44
using target database control file instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 05/29/2014 20:53:44
RMAN-12010: automatic channel allocation initialization failed
RMAN-06403: could not obtain a fully authorized session
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory

RMAN>

RMAN> startup nomount #上面的错误是数据库没有nomount

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/oracle/app/oracle/product/11.2.0/dbs/initPROD.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2260088 bytes
Variable Size                281019272 bytes
Database Buffers             780140544 bytes
Redo Buffers                   5517312 bytes

RMAN> restore spfile to '/u01/oracle/app/oracle/product/11.2.0/dbs/spfilePROD.ora' from '/u01/backup/suys_spfile_09p9eqo4_1_1_20140528';

Starting restore at 2014-05-29 20:54:48
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=171 device type=DISK

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/backup/suys_spfile_09p9eqo4_1_1_20140528
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2014-05-29 20:54:50

RMAN>

RMAN> restore controlfile to '/u01/oracle/app/oracle/oradata/PROD/controfile1.ctl' from '/u01/backup/ctl_file_08p9eqnu_1_1_20140528';

Starting restore at 2014-05-29 20:55:10
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2014-05-29 20:55:11

通过上面的指令,就得到了备份集里面的spfile和controfile文件,后面还要处理才能给目标数据库用的

步骤三:得到和修改pfile路径

[oracle@shu4 ]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu May 29 20:56:36 2014

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create pfile from spfile;

File created.

SQL> shutdown immediate
ORA-01507: database not mounted

ORACLE instance shut down.
SQL>

因为spfile是二进制的,所以我们要用pfile来修改目标数据对应的属性

[oracle@shu4 ]$ cat initPROD.ora
PROD.__db_cache_size=1140850688
PROD.__java_pool_size=16777216
PROD.__large_pool_size=33554432
PROD.__oracle_base='/u01/oracle/app/oracle'#ORACLE_BASE set from environment
PROD.__pga_aggregate_target=1795162112
PROD.__sga_target=1560281088
PROD.__shared_io_pool_size=0
PROD.__shared_pool_size=352321536
PROD.__streams_pool_size=0
*.audit_file_dest='/u01/oracle/app/oracle/admin/PROD/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/oracle/app/oracle/oradata/PROD/controfile1.ctl','/u01/oracle/app/oracle/oradata/PROD/controfile2.ctl'
*.db_block_size=8192
*.db_create_file_dest=''
*.db_domain=''
*.db_name='PROD'
*.db_recovery_file_dest=''
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/u01/oracle/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=PRODXDB)'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=1789919232
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=1556086784
*.undo_tablespace='UNDOTBS1'

去掉和修改成实际目标数据库对于的路径。

步骤四:准备新库控制文件

[oracle@shu4 ]$ pwd
/u01/oracle/app/oracle/oradata/PROD
[oracle@shu4 ]$
[oracle@shu4 ]$ ls
controfile1.ctl
[oracle@shu4 ]$
[oracle@shu4 ]$ cp controfile1.ctl controfile2.ctl
[oracle@shu4 ]$
[oracle@shu4 ]$ ll
total 19072
-rw-r----- 1 oracle oinstall 9748480 May 29 21:04 controfile1.ctl
-rw-r----- 1 oracle oinstall 9748480 May 29 21:04 controfile2.ctl
[oracle@shu4 ]$

根据刚才修改后的pfile,把刚才从备份集得到的控制文件放到应该在的位置

步骤五:数据库进入mount状态

SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup nomount pfile=/u01/oracle/app/oracle/product/11.2.0/dbs/initPROD.ora
ORACLE instance started.

Total System Global Area 1553305600 bytes
Fixed Size                  2253544 bytes
Variable Size             452988184 bytes
Database Buffers         1090519040 bytes
Redo Buffers                7544832 bytes
SQL>
SQL> create spfile from pfile;

File created.

SQL> shutdown immediate
ORA-01507: database not mounted

ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.

Total System Global Area 1553305600 bytes
Fixed Size                  2253544 bytes
Variable Size             452988184 bytes
Database Buffers         1090519040 bytes
Redo Buffers                7544832 bytes
SQL>
SQL> alter database mount;

Database altered.

把刚才修改的pfile生成spfile后,数据库进入mount状态。。可以直接start mount的。。上面的例子是我手误。。

步骤六:RMAN恢复

[oracle@shu4 ]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Thu May 29 21:11:08 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD (DBID=260237162, not open)

RMAN>

RMAN> run{
2>   set newname for datafile 1  to  '/u01/oracle/app/oracle/oradata/PROD/system.dbf';   #修改成目标数据库的路径
3>   set newname for datafile 2  to  '/u01/oracle/app/oracle/oradata/PROD/sysaux.dbf';
4>   set newname for datafile 3  to  '/u01/oracle/app/oracle/oradata/PROD/undotbs1.dbf';
5>   set newname for datafile 4  to  '/u01/oracle/app/oracle/oradata/PROD/users.dbf';
6>   set newname for datafile 5  to  '/u01/oracle/app/oracle/oradata/PROD/example.dbf';
7>   restore database;
8>   switch datafile all;
9>   recover database;
10> }

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 2014-05-29 21:12:37
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=135 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=11 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=136 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00003 to /u01/oracle/app/oracle/oradata/PROD/undotbs1.dbf
channel ORA_DISK_1: restoring datafile 00005 to /u01/oracle/app/oracle/oradata/PROD/example.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/suys_lev0_03p9eqie_1_1_20140528
channel ORA_DISK_2: starting datafile backup set restore
channel ORA_DISK_2: specifying datafile(s) to restore from backup set
channel ORA_DISK_2: restoring datafile 00002 to /u01/oracle/app/oracle/oradata/PROD/sysaux.dbf
channel ORA_DISK_2: restoring datafile 00004 to /u01/oracle/app/oracle/oradata/PROD/users.dbf
channel ORA_DISK_2: reading from backup piece /u01/backup/suys_lev0_02p9eqie_1_1_20140528
channel ORA_DISK_3: starting datafile backup set restore
channel ORA_DISK_3: specifying datafile(s) to restore from backup set
channel ORA_DISK_3: restoring datafile 00001 to /u01/oracle/app/oracle/oradata/PROD/system.dbf
channel ORA_DISK_3: reading from backup piece /u01/backup/suys_lev0_01p9eqie_1_1_20140528
channel ORA_DISK_3: piece handle=/u01/backup/suys_lev0_01p9eqie_1_1_20140528 tag=SUYS_LEV0
channel ORA_DISK_3: restored backup piece 1
channel ORA_DISK_3: restore complete, elapsed time: 00:02:03
channel ORA_DISK_1: piece handle=/u01/backup/suys_lev0_03p9eqie_1_1_20140528 tag=SUYS_LEV0
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:02:09
channel ORA_DISK_2: piece handle=/u01/backup/suys_lev0_02p9eqie_1_1_20140528 tag=SUYS_LEV0
channel ORA_DISK_2: restored backup piece 1
channel ORA_DISK_2: restore complete, elapsed time: 00:02:30
Finished restore at 2014-05-29 21:15:10

datafile 1 switched to datafile copy
input datafile copy RECID=7 STAMP=848870110 file name=/u01/oracle/app/oracle/oradata/PROD/system.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=848870110 file name=/u01/oracle/app/oracle/oradata/PROD/sysaux.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=848870110 file name=/u01/oracle/app/oracle/oradata/PROD/undotbs1.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=848870110 file name=/u01/oracle/app/oracle/oradata/PROD/users.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=11 STAMP=848870110 file name=/u01/oracle/app/oracle/oradata/PROD/example.dbf

Starting recover at 2014-05-29 21:15:11
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=5
channel ORA_DISK_1: reading from backup piece /u01/backup/arch_06p9eqni_1_1_20140528
channel ORA_DISK_2: starting archived log restore to default destination
channel ORA_DISK_2: restoring archived log
archived log thread=1 sequence=6
channel ORA_DISK_2: reading from backup piece /u01/backup/arch_07p9eqni_1_1_20140528
channel ORA_DISK_2: piece handle=/u01/backup/arch_07p9eqni_1_1_20140528 tag=ARC_BAK
channel ORA_DISK_2: restored backup piece 1
channel ORA_DISK_2: restore complete, elapsed time: 00:00:02
channel ORA_DISK_1: piece handle=/u01/backup/arch_06p9eqni_1_1_20140528 tag=ARC_BAK
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
archived log file name=/u01/oracle/app/oracle/product/11.2.0/dbs/arch1_5_848398840.dbf thread=1 sequence=5
archived log file name=/u01/oracle/app/oracle/product/11.2.0/dbs/arch1_6_848398840.dbf thread=1 sequence=6
unable to find archived log
archived log thread=1 sequence=7
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 05/29/2014 21:15:24
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 7 and starting SCN of 992750
--之前在线日志文件未生成
--确认在mount状态下做基于时间点或者scn的不完全恢复
RMAN> recover database until scn 992750;

Starting recover at 2014-05-29 21:15:58
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 2014-05-29 21:15:59


步骤七:mount状态修改online redo文件路径

SQL>
SQL> alter database rename file '+DATA/prod/onlinelog/group_3.266.848398863' to '/u01/oracle/app/oracle/oradata/PROD/log3a.log';

Database altered.

SQL> alter database rename file '+DATA/prod/onlinelog/group_3.267.848398867' to '/u01/oracle/app/oracle/oradata/PROD/log3b.log';

Database altered.

SQL> alter database rename file '+DATA/prod/onlinelog/group_2.264.848398851' to '/u01/oracle/app/oracle/oradata/PROD/log2a.log';

Database altered.

SQL> alter database rename file '+DATA/prod/onlinelog/group_2.265.848398857' to '/u01/oracle/app/oracle/oradata/PROD/log2b.log';

Database altered.

SQL> alter database rename file '+DATA/prod/onlinelog/group_1.262.848398841' to '/u01/oracle/app/oracle/oradata/PROD/log1a.log';

Database altered.

SQL> alter database rename file '+DATA/prod/onlinelog/group_1.263.848398847' to '/u01/oracle/app/oracle/oradata/PROD/log1b.log';

Database altered.

SQL> set linesize 190
SQL> col member format a60
SQL> select * from v$logfile;

GROUP# STATUS  TYPE    MEMBER                                                       IS_
---------- ------- ------- ------------------------------------------------------------ ---
3         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log3a.log                NO
3         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log3b.log                NO
2         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log2a.log                NO
2         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log2b.log                NO
1         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log1a.log                NO
1         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log1b.log                NO

6 rows selected.

SQL>


步骤八:open resetlogs数据库,temp文件善后

SQL> select * from v$logfile;

GROUP# STATUS  TYPE    MEMBER                                                       IS_
---------- ------- ------- ------------------------------------------------------------ ---
3         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log3a.log                NO
3         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log3b.log                NO
2         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log2a.log                NO
2         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log2b.log                NO
1         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log1a.log                NO
1         ONLINE  /u01/oracle/app/oracle/oradata/PROD/log1b.log                NO

6 rows selected.

SQL>
SQL> alter database open resetlogs;

Database altered.

SQL> select name from v$tempfile;

NAME
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+DATA/prod/tempfile/temp.268.848398887

SQL> alter tablespace temp add tempfile '/u01/oracle/app/oracle/oradata/PROD/temp.dbf' size 100m;

Tablespace altered.

SQL> select name from v$tempfile;

NAME
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+DATA/prod/tempfile/temp.268.848398887
/u01/oracle/app/oracle/oradata/PROD/temp.dbf

SQL> alter tablespace temp drop tempfile '+DATA/prod/tempfile/temp.268.848398887';

Tablespace altered.

SQL> select name from v$tempfile;

NAME
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/u01/oracle/app/oracle/oradata/PROD/temp.dbf

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 1553305600 bytes
Fixed Size                  2253544 bytes
Variable Size             452988184 bytes
Database Buffers         1090519040 bytes
Redo Buffers                7544832 bytes
Database mounted.
Database opened.
SQL> create table aa( name varchar2(20 ));

Table created.

SQL> insert into aa values('aa');

1 row created.

SQL> commit;

Commit complete.


这样数据库就迁移好了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: