网络很多帖子介绍的都是不完全恢复的方法.
注意: 迁移前要保证是归档状态下.
1 迁移在线重做日志文件
迁移重做日志的方法与不完全恢复的做法是一致的。在ASM上有两个磁盘组,一个是DATA,一个是FRA。
1.1 修改参数
SQL> show parameter db_create;
NAME TYPE VALUE
------------------------------ ----------- -------------
db_create_file_dest string
db_create_online_log_dest_1 string
db_create_online_log_dest_2 string
db_create_online_log_dest_3 string
db_create_online_log_dest_4 string
db_create_online_log_dest_5 string
SQL> alter system set db_create_online_log_dest_1 = '+DATA';
System altered.
SQL> alter system set db_create_file_dest = '+DATA';
System altered.
SQL> alter system set db_recovery_file_dest = '+FRA';
System altered.
SQL> show parameter db_create;
NAME TYPE VALUE
------------------------------ ----------- -------------
db_create_file_dest string +DATA
db_create_online_log_dest_1 string +DATA
db_create_online_log_dest_2 string
db_create_online_log_dest_3 string
db_create_online_log_dest_4 string
db_create_online_log_dest_5 string
SQL> show parameter db_recovery
NAME TYPE VALUE
------------------------------- ----------- -------------
db_recovery_file_dest string +FRA
db_recovery_file_dest_size big integer 2G
1.2 增加日志组
增加日志组,新的日志组路径指向ASM,并删除旧的日志组
SQL> alter database add logfile group 4 size 25M;
Database altered.
SQL> alter database add logfile group 5 size 25M;
Database altered.
SQL> alter database add logfile group 6 size 25M;
Database altered.
SQL> select group#,status from v$log;
GROUP# STATUS
---------- -------------
1 INACTIVE
2 INACTIVE
3 CURRENT
4 UNUSED
5 UNUSED
6 UNUSED
6 rows selected.
1.3 删除日志组
SQL> alter database drop logfile group 1;
Database altered.
SQL> alter database drop logfile group 2;
Database altered.
SQL> alter system switch logfile;
System altered.
SQL> alter system checkpoint;
System altered.
SQL> alter database drop logfile group 3;
Database altered.
1.4 查看ASM日志组
此时可以看到在ASM上的日志组信息:
[oracle@cent4 ~]$ export ORACLE_SID=+ASM
[oracle@cent4 ~]$ asmcmd
ASMCMD> ls
DATA/
FRA/
ASMCMD> cd data
ASMCMD> cd test
ASMCMD> cd onlinelog
ASMCMD> ls
group_4.256.752606807
group_5.257.752606815
group_6.258.752606821
ASMCMD> pwd
+data/test/onlinelog
2 迁移数据文件
迁移数据文件要在mount的状态下进行。
2.1 原数据库切换到mount状态下
SQL> shutdown immediate
SQL> startup mount
2.2 在rman下迁移数据文件
[oracle@cent4 ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on 星期二 5月 31 17:29:36 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: TEST (DBID=2050570208, not open)
RMAN> backup as copy database format '+DATA';
Starting backup at 2011-05-31 17:29:54
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=100 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001 name=/oradata/test/system01.dbf
output filename=+DATA/test/datafile/system.259.752606999 tag=TAG20110531T172955 recid=2 stamp=752607035
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile copy
input datafile fno=00003 name=/oradata/test/sysaux01.dbf
output filename=+DATA/test/datafile/sysaux.260.752607043 tag=TAG20110531T172955 recid=3 stamp=752607059
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile fno=00005 name=/oradata/test/example01.dbf
output filename=+DATA/test/datafile/example.261.752607067 tag=TAG20110531T172955 recid=4 stamp=752607075
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile fno=00002 name=/oradata/test/undotbs01.dbf
output filename=+DATA/test/datafile/undotbs1.262.752607083 tag=TAG20110531T172955 recid=5 stamp=752607084
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile fno=00004 name=/oradata/test/users01.dbf
output filename=+DATA/test/datafile/users.263.752607089 tag=TAG20110531T172955 recid=6 stamp=752607089
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
copying current control file
output filename=+DATA/test/controlfile/backup.264.752607091 tag=TAG20110531T172955 recid=7 stamp=752607091
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 2011-05-31 17:31:34
channel ORA_DISK_1: finished piece 1 at 2011-05-31 17:31:35
piece handle=+DATA/test/backupset/2011_05_31/nnsnf0_tag20110531t172955_0.265.752607095 tag=TAG20110531T172955 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2011-05-31 17:31:35
RMAN> switch database to copy;
datafile 1 switched to datafile copy "+DATA/test/datafile/system.259.752606999"
datafile 2 switched to datafile copy "+DATA/test/datafile/undotbs1.262.752607083"
datafile 3 switched to datafile copy "+DATA/test/datafile/sysaux.260.752607043"
datafile 4 switched to datafile copy "+DATA/test/datafile/users.263.752607089"
datafile 5 switched to datafile copy "+DATA/test/datafile/example.261.752607067"
2.3 查看ASM数据文件
在ASMCMD中看到的结果:
ASMCMD> ls
EXAMPLE.261.752607067
SYSAUX.260.752607043
SYSTEM.259.752606999
UNDOTBS1.262.752607083
USERS.263.752607089
3 迁移控制文件
3.1 从跟踪文件中获取建库脚本
最好要在做完日志文件迁移与数据文件迁移后, 再生成控制文件. 这样子, 生成的脚本中对应数据文件与日志文件的路径等参数不要做修改.
SQL> alter database backup controlfile to trace as '/home/oracle/ctl.txt';
编缉控制文件后(删头去尾),得到如下的内容:
[oracle@cent4 ~]$ cat ctl.txt
CREATE CONTROLFILE REUSE DATABASE "TEST" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 4 '+DATA/test/onlinelog/group_4.256.752606807' SIZE 25M,
GROUP 5 '+DATA/test/onlinelog/group_5.257.752606815' SIZE 25M,
GROUP 6 '+DATA/test/onlinelog/group_6.258.752606821' SIZE 25M
DATAFILE
'+DATA/test/datafile/system.259.752606999',
'+DATA/test/datafile/undotbs1.262.752607083',
'+DATA/test/datafile/sysaux.260.752607043',
'+DATA/test/datafile/users.263.752607089',
'+DATA/test/datafile/example.261.752607067'
CHARACTER SET ZHS16GBK
;
3.2 切换控制文件路径
SQL> shutdown immediate
SQL> startup nomount
SQL> show parameter control_files
NAME TYPE VALUE
---------------- ---------------- ------------------------------
control_files string /oradata/test/control01.ctl,
/oradata/test/control02.ctl,
/oradata/test/control03.ctl
SQL> alter system set control_files='+DATA','+FRA' scope=spfile;
System altered.
3.3 在nomount状态下切换控制文件路径
这里还要再重启一下, 保证修改的控制文件路径的参数生效.
SQL> shutdown immediate
SQL> startup nomount
SQL> @/home/oracle/ctl.txt
Control file created.
3.4 打开数据库并创建临时表空间
要生成临时文件, 在脚本中这一段被我删去了.
SQL> alter database open;
Database altered.
SQL> alter tablespace temp add tempfile size 20M;
Tablespace altered.
4 迁移参数文件
4.1 切换参数文件路径
SQL> create pfile from spfile;
File created.
SQL> show parameter spfile
NAME TYPE VALUE
------------------ ----------- ------------------------------------------------------
spfile string /u01/app/oracle/product/10.2.0/db_1/dbs/spfiletest.ora
SQL> create spfile='+DATA' from pfile;
File created.
删除spfile, 编辑pfile, 保证路径指向ASM中的参数文件
[oracle@cent4 dbs]$ rm spfiletest.ora
[oracle@cent4 dbs]$ vi inittest.ora
修改参数文件inittest.ora,内容改成如下:
spfile=+data/orcl/PARAMETERFILE/spfile.268.752608305
4.2 查看参数文件
ASMCMD> ls
BACKUPSET/
CONTROLFILE/
DATAFILE/
ONLINELOG/
PARAMETERFILE/
TEMPFILE/
ASMCMD> cd parameterfile
ASMCMD> ls
spfile.268.752608305
ASMCMD> pwd
+data/test/parameterfile
5 验证迁移
重启后验证参数文件与三大数据库文件.
5.1 参数文件
SQL> show parameter spfile
NAME TYPE VALUE
------------------ ----------- -----------------------------------------------
spfile string +DATA/orcl/parameterfile/spfile.268.752608305
5.2 控制文件
SQL> show parameter control_files
NAME TYPE VALUE
------------------ ----------- ---------------------------------------------
control_files string +DATA/test/controlfile/current.266.752607653,
+FRA/test/controlfile/current.257.752607653
5.3 数据文件
SQL> col file_name format a50
SQL> col tablespace_name format a20
SQL> select file_name, tablespace_name from dba_data_files;
FILE_NAME TABLESPACE_NAME
-------------------------------------------------- --------------------
+DATA/test/datafile/example.261.752607067 EXAMPLE
+DATA/test/datafile/users.263.752607089 USERS
+DATA/test/datafile/sysaux.260.752607043 SYSAUX
+DATA/test/datafile/undotbs1.262.752607083 UNDOTBS1
+DATA/test/datafile/system.259.752606999 SYSTEM
5.4 日志文件
SQL> col member format a45
SQL> select * from v$logfile;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- ------- --------------------------------------------- ---
4 STALE ONLINE +DATA/test/onlinelog/group_4.256.752606807 NO
6 STALE ONLINE +DATA/test/onlinelog/group_6.258.752606821 NO
5 ONLINE +DATA/test/onlinelog/group_5.257.752606815 NO